3434import lines
3535
3636from matplotlib .mlab import meshgrid , detrend_none , detrend_linear , \
37- window_none , window_hanning , linspace , prctile
37+ window_none , window_hanning , prctile , linspace
3838from matplotlib .numerix .mlab import flipud , amin , amax , dot
3939
4040from matplotlib import rcParams
41- from patches import Patch , Rectangle , Circle , Polygon , Arrow , Wedge , Shadow , FancyArrow , bbox_artist
41+ from patches import Patch , Rectangle , Circle , Polygon , RegularPolygon ,\
42+ Arrow , Wedge , Shadow , FancyArrow , bbox_artist
4243import table
4344from text import Text , TextWithDash , Annotation , _process_text_args
4445from transforms import Bbox , Point , Value , Affine , NonseparableTransformation
@@ -2803,6 +2804,7 @@ def xcorr(self, x, y, normed=False, detrend=detrend_none, usevlines=False,
28032804 kwargs .setdefault ('marker' , 'o' )
28042805 kwargs .setdefault ('linestyle' , 'None' )
28052806 a , = self .plot (lags , c , ** kwargs )
2807+ b = None
28062808 return lags , c , a , b
28072809 xcorr .__doc__ = dedent (xcorr .__doc__ ) % artist .kwdocd
28082810
@@ -5224,7 +5226,7 @@ class PolarAxes(Axes):
52245226
52255227 """
52265228
5227- RESOLUTION = 200
5229+ RESOLUTION = 100
52285230
52295231 def __init__ (self , * args , ** kwarg ):
52305232 """
@@ -5291,13 +5293,15 @@ def cla(self):
52915293 self ._set_artist_props (self .title )
52925294
52935295
5294- self .thetas = linspace (0 ,2 * math .pi , self .RESOLUTION )
5296+ self .thetas = linspace (0 , 2 * math .pi , self .RESOLUTION )
5297+
52955298 verts = zip (self .thetas , ones (self .RESOLUTION ))
52965299 self .axesPatch = Polygon (
52975300 verts ,
52985301 facecolor = self ._axisbg ,
52995302 edgecolor = rcParams ['axes.edgecolor' ],
53005303 )
5304+
53015305
53025306
53035307 self .axesPatch .set_figure (self .figure )
@@ -5313,10 +5317,19 @@ def cla(self):
53135317 self .rformatter = ScalarFormatter ()
53145318 self .rformatter .set_view_interval (self .rintv )
53155319 self .rformatter .set_data_interval (self .rintd )
5316- self .rlocator = AutoLocator ()
5320+
5321+ class RadialLocator (AutoLocator ):
5322+ 'enforce strictly positive radial ticks'
5323+
5324+ def __call__ (self ):
5325+ ticks = AutoLocator .__call__ (self )
5326+ return [t for t in ticks if t > 0 ]
5327+
5328+ self .rlocator = RadialLocator ()
53175329 self .rlocator .set_view_interval (self .rintv )
53185330 self .rlocator .set_data_interval (self .rintd )
53195331
5332+
53205333 angles = arange (0 , 360 , 45 )
53215334 radii = arange (0.2 , 1.1 , 0.2 )
53225335 self .set_thetagrids (angles )
@@ -5334,8 +5347,8 @@ def get_children(self):
53345347 children .extend (self .texts )
53355348 children .extend (self .artists )
53365349 children .extend (self .images )
5337- # if self.legend_ is not None:
5338- # children.append(self.legend_)
5350+ if self .legend_ is not None :
5351+ children .append (self .legend_ )
53395352 children .extend (self .collections )
53405353 children .append (self .title )
53415354 children .append (self .axesPatch )
@@ -5351,12 +5364,15 @@ def grid(self, b):
53515364 self ._gridOn = b
53525365
53535366 def regrid (self , rmax ):
5367+ rmax = float (rmax )
53545368 self .axesPatch .xy = zip (self .thetas , rmax * ones (self .RESOLUTION ))
5369+
53555370 val = rmax * math .sqrt (2 )
53565371 self .viewLim .intervaly ().set_bounds (val , val )
53575372
53585373 ticks = self .rlocator ()
53595374 self .set_rgrids (ticks )
5375+ self .rformatter .set_locs (ticks )
53605376
53615377 for t in self .thetagridlabels :
53625378 t .set_y (1.05 * rmax )
@@ -5372,7 +5388,7 @@ def autoscale_view(self, scalex=True, scaley=True):
53725388 self .rintv .set_bounds (rmin , rmax )
53735389 self .regrid (rmax )
53745390
5375- def set_rgrids (self , radii , labels = None , angle = 22.5 , ** kwargs ):
5391+ def set_rgrids (self , radii , labels = None , angle = 22.5 , rpad = 0.05 , ** kwargs ):
53765392 """
53775393 set the radial locations and labels of the r grids
53785394
@@ -5383,6 +5399,9 @@ def set_rgrids(self, radii, labels=None, angle=22.5, **kwargs):
53835399
53845400 if labels is None, the self.rformatter will be used
53855401
5402+ rpad is a fraction of the max of radii which will pad each of
5403+ the radial labels in the radial direction.
5404+
53865405 Return value is a list of lines, labels where the lines are
53875406 matplotlib.Line2D instances and the labels are matplotlib.Text
53885407 instances
@@ -5393,12 +5412,21 @@ def set_rgrids(self, radii, labels=None, angle=22.5, **kwargs):
53935412 ACCEPTS: sequence of floats
53945413 """
53955414
5415+
5416+
5417+ rmin = nx .amin (radii )
5418+ if rmin <= 0 :
5419+ raise ValueError ('radial grids must be strictly positive' )
5420+
5421+ rpad = rpad * max (radii )
53965422 popall (self .rgridlines )
5397- theta = linspace (0 ,2 * math .pi , self .RESOLUTION )
5423+
5424+ theta = linspace (0. , 2 * math .pi , self .RESOLUTION )
53985425 ls = rcParams ['grid.linestyle' ]
53995426 color = rcParams ['grid.color' ]
54005427 lw = rcParams ['grid.linewidth' ]
54015428
5429+ rmax = self .get_rmax ()
54025430 for r in radii :
54035431 r = ones (self .RESOLUTION )* r
54045432 line = Line2D (theta , r , linestyle = ls , color = color , linewidth = lw )
@@ -5407,7 +5435,6 @@ def set_rgrids(self, radii, labels=None, angle=22.5, **kwargs):
54075435 line .set_transform (self .transData )
54085436 self .rgridlines .append (line )
54095437
5410-
54115438 popall (self .rgridlabels )
54125439
54135440
@@ -5418,7 +5445,7 @@ def set_rgrids(self, radii, labels=None, angle=22.5, **kwargs):
54185445 if labels is None :
54195446 labels = [self .rformatter (r ,0 ) for r in radii ]
54205447 for r ,l in zip (radii , labels ):
5421- t = Text (angle / 180. * math .pi , r , l ,
5448+ t = Text (angle / 180. * math .pi , r + rpad , l ,
54225449 fontproperties = props , color = color ,
54235450 horizontalalignment = 'center' , verticalalignment = 'center' )
54245451 t .set_transform (self .transData )
@@ -5460,7 +5487,8 @@ def set_thetagrids(self, angles, labels=None, fmt='%d', frac = 1.1,
54605487 color = rcParams ['grid.color' ]
54615488 lw = rcParams ['grid.linewidth' ]
54625489
5463- r = linspace (0 , self .get_rmax (), self .RESOLUTION )
5490+ rmax = self .get_rmax ()
5491+ r = linspace (0. , rmax , self .RESOLUTION )
54645492 for a in angles :
54655493 theta = ones (self .RESOLUTION )* a / 180. * math .pi
54665494 line = Line2D (theta , r , linestyle = ls , color = color , linewidth = lw )
@@ -5472,7 +5500,7 @@ def set_thetagrids(self, angles, labels=None, fmt='%d', frac = 1.1,
54725500 color = rcParams ['xtick.color' ]
54735501
54745502 props = FontProperties (size = rcParams ['xtick.labelsize' ])
5475- r = frac * self . get_rmax ()
5503+ r = frac * rmax
54765504 if labels is None :
54775505 labels = [fmt % a for a in angles ]
54785506 for a ,l in zip (angles , labels ):
@@ -5498,51 +5526,59 @@ def draw(self, renderer):
54985526 self .transData .freeze () # eval the lazy objects
54995527 self .transAxes .freeze () # eval the lazy objects
55005528
5501- tverts = self .transData .seq_xy_tups (self .axesPatch .get_verts ())
5529+ verts = self .axesPatch .get_verts ()
5530+ tverts = self .transData .seq_xy_tups (verts )
55025531
5503- def make_clippath ():
5504- clippath = agg .path_storage ()
5505- for i , xy in enumerate (tverts ):
5506- if i == 0 : clippath .move_to (* xy )
5507- else : clippath .line_to (* xy )
5508- clippath .close_polygon ()
5509- return clippath
5532+ #for i,v,t in zip(range(len(verts)), verts, tverts):
5533+ # print i,v,t
5534+
5535+
55105536
5537+ l ,b ,w ,h = self .figure .bbox .get_bounds ()
55115538 clippath = agg .path_storage ()
55125539 for i , xy in enumerate (tverts ):
5513- if i == 0 : clippath .move_to (* xy )
5514- else : clippath .line_to (* xy )
5540+ x ,y = xy
5541+ y = h - y
5542+ if i == 0 : clippath .move_to (x , y )
5543+ else : clippath .line_to (x , y )
55155544 clippath .close_polygon ()
55165545
55175546 #self._update_axes()
55185547 if self .axison :
55195548 if self ._frameon : self .axesPatch .draw (renderer )
55205549
55215550 if self ._gridOn :
5522- for l in self .rgridlines + self .thetagridlines :
5523- #l.set_clip_path(make_clippath())
5524- #l.set_clip_path(clippath)
5551+ for l in self .rgridlines :
5552+ l .set_clip_path (clippath )
55255553 l .draw (renderer )
55265554
5555+ for l in self .thetagridlines :
5556+ l .set_clip_path (clippath )
5557+ l .draw (renderer )
5558+
55275559 for line in self .lines :
5528- #line.set_clip_path(make_clippath())
55295560 line .set_clip_path (clippath )
55305561
5531- for t in self .thetagridlabels + self .rgridlabels :
5532- t .draw (renderer )
5533-
55345562 artists = []
55355563 artists .extend (self .lines )
55365564 artists .extend (self .texts )
55375565 artists .extend (self .collections )
55385566 artists .extend (self .patches )
55395567 artists .extend (self .artists )
5568+
55405569 dsu = [ (a .zorder , a ) for a in artists ]
55415570 dsu .sort ()
55425571
55435572 for zorder , a in dsu :
55445573 a .draw (renderer )
55455574
5575+
5576+ for t in self .thetagridlabels + self .rgridlabels :
5577+ t .draw (renderer )
5578+
5579+ if self .legend_ is not None :
5580+ self .legend_ .draw (renderer )
5581+
55465582 self .title .draw (renderer )
55475583
55485584
@@ -5614,12 +5650,6 @@ def toggle_log_lineary(self):
56145650 'toggle between log and linear axes ignored for polar'
56155651 pass
56165652
5617- def legend (self , * args , ** kwargs ):
5618- """
5619- LEGEND(*args, **kwargs)
5620- Not implemented for polar yet -- use figlegend
5621- """
5622- raise NotImplementedError ('legend not implemented for polar yet -- use figlegend' )
56235653
56245654 def table (self , * args , ** kwargs ):
56255655 """
0 commit comments