Skip to content

Commit 2866613

Browse files
committed
manually merge pull request 146 (add textcolor kwarg to
drawmeridians/drawparallels)
1 parent 0e2afae commit 2866613

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

Changelog

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version 1.0.8 (not yet released)
22
--------------------------------
3+
* add 'textcolor' kwarg to drawmeridians and drawparallels (issue 145).
34
* don't assume grid is regular when adding cyclic point in addcyclic.
45
New kwargs 'axis' and 'cyclic' added. More than one array
56
can be handled at a time, as long as the last one is longitude. Issue 139.

lib/mpl_toolkits/basemap/__init__.py

+25-22
Original file line numberDiff line numberDiff line change
@@ -2217,10 +2217,10 @@ def readshapefile(self,shapefile,name,drawbounds=True,zorder=None,
22172217
self.__dict__[name+'_info']=attributes
22182218
return info
22192219

2220-
def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
2220+
def drawparallels(self,circles,color='k',textcolor='k',linewidth=1.,zorder=None, \
22212221
dashes=[1,1],labels=[0,0,0,0],labelstyle=None, \
22222222
fmt='%g',xoffset=None,yoffset=None,ax=None,latmax=None,
2223-
**kwargs):
2223+
**text_kwargs):
22242224
"""
22252225
Draw and label parallels (latitude lines) for values (in degrees)
22262226
given in the sequence ``circles``.
@@ -2231,6 +2231,7 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
22312231
Keyword Description
22322232
============== ====================================================
22332233
color color to draw parallels (default black).
2234+
textcolor color to draw labels (default black).
22342235
linewidth line width for parallels (default 1.)
22352236
zorder sets the zorder for parallels (if not specified,
22362237
uses default zorder for matplotlib.lines.Line2D
@@ -2259,7 +2260,7 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
22592260
ax axes instance (overrides default axes instance)
22602261
latmax absolute value of latitude to which meridians are drawn
22612262
(default is 80).
2262-
\**kwargs additional keyword arguments controlling text
2263+
\**text_kwargs additional keyword arguments controlling text
22632264
for labels that are passed on to
22642265
the text method of the axes instance (see
22652266
matplotlib.pyplot.text documentation).
@@ -2271,6 +2272,7 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
22712272
associated with each parallel. Deleting an item from the
22722273
dictionary removes the corresponding parallel from the plot.
22732274
"""
2275+
text_kwargs['color']=textcolor # pass textcolor kwarg on to ax.text
22742276
# if celestial=True, don't use "N" and "S" labels.
22752277
if labelstyle is None and self.celestial:
22762278
labelstyle="+/-"
@@ -2446,13 +2448,13 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
24462448
xlab = xlab-xoffset
24472449
if self.projection in _pseudocyl:
24482450
if lat>0:
2449-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='bottom',**kwargs)
2451+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='bottom',**text_kwargs)
24502452
elif lat<0:
2451-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='top',**kwargs)
2453+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='top',**text_kwargs)
24522454
else:
2453-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='center',**kwargs)
2455+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='center',**text_kwargs)
24542456
else:
2455-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='center',**kwargs)
2457+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='right',verticalalignment='center',**text_kwargs)
24562458
elif side == 'r':
24572459
if self.projection in _pseudocyl:
24582460
if self.celestial:
@@ -2464,17 +2466,17 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
24642466
xlab = xlab+xoffset
24652467
if self.projection in _pseudocyl:
24662468
if lat>0:
2467-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='bottom',**kwargs)
2469+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='bottom',**text_kwargs)
24682470
elif lat<0:
2469-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='top',**kwargs)
2471+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='top',**text_kwargs)
24702472
else:
2471-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='center',**kwargs)
2473+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='center',**text_kwargs)
24722474
else:
2473-
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='center',**kwargs)
2475+
t=ax.text(xlab,yy[n],latlab,horizontalalignment='left',verticalalignment='center',**text_kwargs)
24742476
elif side == 'b':
2475-
t = ax.text(xx[n],self.llcrnry-yoffset,latlab,horizontalalignment='center',verticalalignment='top',**kwargs)
2477+
t = ax.text(xx[n],self.llcrnry-yoffset,latlab,horizontalalignment='center',verticalalignment='top',**text_kwargs)
24762478
else:
2477-
t = ax.text(xx[n],self.urcrnry+yoffset,latlab,horizontalalignment='center',verticalalignment='bottom',**kwargs)
2479+
t = ax.text(xx[n],self.urcrnry+yoffset,latlab,horizontalalignment='center',verticalalignment='bottom',**text_kwargs)
24782480
if t is not None: linecolls[lat][1].append(t)
24792481

24802482
# set axes limits to fit map region.
@@ -2501,10 +2503,10 @@ def drawparallels(self,circles,color='k',linewidth=1.,zorder=None, \
25012503
l.set_clip_path(c)
25022504
return pardict
25032505

2504-
def drawmeridians(self,meridians,color='k',linewidth=1., zorder=None,\
2506+
def drawmeridians(self,meridians,color='k',textcolor='k',linewidth=1., zorder=None,\
25052507
dashes=[1,1],labels=[0,0,0,0],labelstyle=None,\
25062508
fmt='%g',xoffset=None,yoffset=None,ax=None,latmax=None,
2507-
**kwargs):
2509+
**text_kwargs):
25082510
"""
25092511
Draw and label meridians (longitude lines) for values (in degrees)
25102512
given in the sequence ``meridians``.
@@ -2515,6 +2517,7 @@ def drawmeridians(self,meridians,color='k',linewidth=1., zorder=None,\
25152517
Keyword Description
25162518
============== ====================================================
25172519
color color to draw meridians (default black).
2520+
textcolor color to draw labels (default black).
25182521
linewidth line width for meridians (default 1.)
25192522
zorder sets the zorder for meridians (if not specified,
25202523
uses default zorder for matplotlib.lines.Line2D
@@ -2543,7 +2546,7 @@ def drawmeridians(self,meridians,color='k',linewidth=1., zorder=None,\
25432546
ax axes instance (overrides default axes instance)
25442547
latmax absolute value of latitude to which meridians are drawn
25452548
(default is 80).
2546-
\**kwargs additional keyword arguments controlling text
2549+
\**text_kwargs additional keyword arguments controlling text
25472550
for labels that are passed on to
25482551
the text method of the axes instance (see
25492552
matplotlib.pyplot.text documentation).
@@ -2555,6 +2558,7 @@ def drawmeridians(self,meridians,color='k',linewidth=1., zorder=None,\
25552558
associated with each meridian. Deleting an item from the
25562559
dictionary removes the correpsonding meridian from the plot.
25572560
"""
2561+
text_kwargs['color']=textcolor # pass textcolor kwarg on to ax.text
25582562
# for cylindrical projections, try to handle wraparound (i.e. if
25592563
# projection is defined in -180 to 0 and user asks for meridians from
25602564
# 180 to 360 to be drawn, it should work)
@@ -2718,13 +2722,13 @@ def addlon(meridians,madd):
27182722
if n >= 0:
27192723
t = None
27202724
if side == 'l':
2721-
t = ax.text(self.llcrnrx-xoffset,yy[n],lonlab,horizontalalignment='right',verticalalignment='center',**kwargs)
2725+
t = ax.text(self.llcrnrx-xoffset,yy[n],lonlab,horizontalalignment='right',verticalalignment='center',**text_kwargs)
27222726
elif side == 'r':
2723-
t = ax.text(self.urcrnrx+xoffset,yy[n],lonlab,horizontalalignment='left',verticalalignment='center',**kwargs)
2727+
t = ax.text(self.urcrnrx+xoffset,yy[n],lonlab,horizontalalignment='left',verticalalignment='center',**text_kwargs)
27242728
elif side == 'b':
2725-
t = ax.text(xx[n],self.llcrnry-yoffset,lonlab,horizontalalignment='center',verticalalignment='top',**kwargs)
2729+
t = ax.text(xx[n],self.llcrnry-yoffset,lonlab,horizontalalignment='center',verticalalignment='top',**text_kwargs)
27262730
else:
2727-
t = ax.text(xx[n],self.urcrnry+yoffset,lonlab,horizontalalignment='center',verticalalignment='bottom',**kwargs)
2731+
t = ax.text(xx[n],self.urcrnry+yoffset,lonlab,horizontalalignment='center',verticalalignment='bottom',**text_kwargs)
27282732

27292733
if t is not None: linecolls[lon][1].append(t)
27302734
# set axes limits to fit map region.
@@ -2813,8 +2817,7 @@ def addlon(meridians,madd):
28132817
if labels[1] and not labels[0] and x >= 0.5*(self.xmin+self.xmax)-xoffset: continue
28142818
if labels[2] and not labels[3] and y >= 0.5*(self.ymin+self.ymax)-yoffset: continue
28152819
if labels[3] and not labels[2] and y <= 0.5*(self.ymin+self.ymax)+yoffset: continue
2816-
t =\
2817-
ax.text(x,y,lonlab,horizontalalignment=horizalign,verticalalignment=vertalign,**kwargs)
2820+
t=ax.text(x,y,lonlab,horizontalalignment=horizalign,verticalalignment=vertalign,**text_kwargs)
28182821
meridict[merid][1].append(t)
28192822
return meridict
28202823

0 commit comments

Comments
 (0)