14
14
import matplotlib .axis as maxis
15
15
from matplotlib import cbook
16
16
from matplotlib import docstring
17
- from matplotlib .patches import Circle
18
- from matplotlib .path import Path
19
- from matplotlib .ticker import Formatter , Locator , FormatStrFormatter
20
- from matplotlib .transforms import Affine2D , Affine2DBase , Bbox , \
21
- BboxTransformTo , IdentityTransform , Transform , TransformWrapper , \
22
- ScaledTranslation , blended_transform_factory , BboxTransformToMaxOnly , \
23
- nonsingular
17
+ import matplotlib .patches as mpatches
18
+ import matplotlib .path as mpath
19
+ import matplotlib .ticker as mticker
20
+ import matplotlib .transforms as mtransforms
24
21
import matplotlib .spines as mspines
25
22
26
23
27
- class PolarTransform (Transform ):
24
+ class PolarTransform (mtransforms . Transform ):
28
25
"""
29
26
The base polar transform. This handles projection *theta* and
30
27
*r* into Cartesian coordinate space *x* and *y*, but does not
@@ -36,7 +33,7 @@ class PolarTransform(Transform):
36
33
is_separable = False
37
34
38
35
def __init__ (self , axis = None , use_rmin = True ):
39
- Transform .__init__ (self )
36
+ mtransforms . Transform .__init__ (self )
40
37
self ._axis = axis
41
38
self ._use_rmin = use_rmin
42
39
@@ -68,22 +65,24 @@ def transform_non_affine(self, tr):
68
65
y [:] = np .where (mask , np .nan , r * np .sin (t ))
69
66
70
67
return xy
71
- transform_non_affine .__doc__ = Transform .transform_non_affine .__doc__
68
+ transform_non_affine .__doc__ = \
69
+ mtransforms .Transform .transform_non_affine .__doc__
72
70
73
71
def transform_path_non_affine (self , path ):
74
72
vertices = path .vertices
75
73
if len (vertices ) == 2 and vertices [0 , 0 ] == vertices [1 , 0 ]:
76
- return Path (self .transform (vertices ), path .codes )
74
+ return mpath . Path (self .transform (vertices ), path .codes )
77
75
ipath = path .interpolated (path ._interpolation_steps )
78
- return Path (self .transform (ipath .vertices ), ipath .codes )
79
- transform_path_non_affine .__doc__ = Transform .transform_path_non_affine .__doc__
76
+ return mpath .Path (self .transform (ipath .vertices ), ipath .codes )
77
+ transform_path_non_affine .__doc__ = \
78
+ mtransforms .Transform .transform_path_non_affine .__doc__
80
79
81
80
def inverted (self ):
82
81
return PolarAxes .InvertedPolarTransform (self ._axis , self ._use_rmin )
83
- inverted .__doc__ = Transform .inverted .__doc__
82
+ inverted .__doc__ = mtransforms . Transform .inverted .__doc__
84
83
85
84
86
- class PolarAffine (Affine2DBase ):
85
+ class PolarAffine (mtransforms . Affine2DBase ):
87
86
"""
88
87
The affine part of the polar projection. Scales the output so
89
88
that maximum radius rests on the edge of the axes circle.
@@ -94,7 +93,7 @@ def __init__(self, scale_transform, limits):
94
93
its bounds that is used is ymax (for the radius maximum).
95
94
The theta range is always fixed to (0, 2pi).
96
95
"""
97
- Affine2DBase .__init__ (self )
96
+ mtransforms . Affine2DBase .__init__ (self )
98
97
self ._scale_transform = scale_transform
99
98
self ._limits = limits
100
99
self .set_children (scale_transform , limits )
@@ -104,17 +103,17 @@ def get_matrix(self):
104
103
if self ._invalid :
105
104
limits_scaled = self ._limits .transformed (self ._scale_transform )
106
105
yscale = limits_scaled .ymax - limits_scaled .ymin
107
- affine = Affine2D () \
106
+ affine = mtransforms . Affine2D () \
108
107
.scale (0.5 / yscale ) \
109
108
.translate (0.5 , 0.5 )
110
109
self ._mtx = affine .get_matrix ()
111
110
self ._inverted = None
112
111
self ._invalid = 0
113
112
return self ._mtx
114
- get_matrix .__doc__ = Affine2DBase .get_matrix .__doc__
113
+ get_matrix .__doc__ = mtransforms . Affine2DBase .get_matrix .__doc__
115
114
116
115
117
- class InvertedPolarTransform (Transform ):
116
+ class InvertedPolarTransform (mtransforms . Transform ):
118
117
"""
119
118
The inverse of the polar transform, mapping Cartesian
120
119
coordinate space *x* and *y* back to *theta* and *r*.
@@ -124,7 +123,7 @@ class InvertedPolarTransform(Transform):
124
123
is_separable = False
125
124
126
125
def __init__ (self , axis = None , use_rmin = True ):
127
- Transform .__init__ (self )
126
+ mtransforms . Transform .__init__ (self )
128
127
self ._axis = axis
129
128
self ._use_rmin = use_rmin
130
129
@@ -160,14 +159,15 @@ def transform_non_affine(self, xy):
160
159
r += rmin
161
160
162
161
return np .concatenate ((theta , r ), 1 )
163
- transform_non_affine .__doc__ = Transform .transform_non_affine .__doc__
162
+ transform_non_affine .__doc__ = \
163
+ mtransforms .Transform .transform_non_affine .__doc__
164
164
165
165
def inverted (self ):
166
166
return PolarAxes .PolarTransform (self ._axis , self ._use_rmin )
167
- inverted .__doc__ = Transform .inverted .__doc__
167
+ inverted .__doc__ = mtransforms . Transform .inverted .__doc__
168
168
169
169
170
- class ThetaFormatter (Formatter ):
170
+ class ThetaFormatter (mticker . Formatter ):
171
171
"""
172
172
Used to format the *theta* tick labels. Converts the native
173
173
unit of radians into degrees and adds a degree symbol.
@@ -190,7 +190,7 @@ def __call__(self, x, pos=None):
190
190
return format_str .format (value = np .rad2deg (x ), digits = digits )
191
191
192
192
193
- class RadialLocator (Locator ):
193
+ class RadialLocator (mticker . Locator ):
194
194
"""
195
195
Used to locate radius ticks.
196
196
@@ -229,7 +229,7 @@ def refresh(self):
229
229
230
230
def view_limits (self , vmin , vmax ):
231
231
vmin , vmax = self .base .view_limits (vmin , vmax )
232
- return nonsingular (min (0 , vmin ), vmax )
232
+ return mtransforms . nonsingular (min (0 , vmin ), vmax )
233
233
234
234
235
235
class PolarAxes (Axes ):
@@ -286,11 +286,12 @@ def _init_axis(self):
286
286
self ._update_transScale ()
287
287
288
288
def _set_lim_and_transforms (self ):
289
- self .transAxes = BboxTransformTo (self .bbox )
289
+ self .transAxes = mtransforms . BboxTransformTo (self .bbox )
290
290
291
291
# Transforms the x and y axis separately by a scale factor
292
292
# It is assumed that this part will have non-linear components
293
- self .transScale = TransformWrapper (IdentityTransform ())
293
+ self .transScale = mtransforms .TransformWrapper (
294
+ mtransforms .IdentityTransform ())
294
295
295
296
# A (possibly non-linear) projection on the (already scaled)
296
297
# data. This one is aware of rmin
@@ -313,14 +314,17 @@ def _set_lim_and_transforms(self):
313
314
# the edge of the axis circle.
314
315
self ._xaxis_transform = (
315
316
self .transPureProjection +
316
- self .PolarAffine (IdentityTransform (), Bbox .unit ()) +
317
+ self .PolarAffine (mtransforms .IdentityTransform (),
318
+ mtransforms .Bbox .unit ()) +
317
319
self .transAxes )
318
320
# The theta labels are moved from radius == 0.0 to radius == 1.1
319
- self ._theta_label1_position = Affine2D ().translate (0.0 , 1.1 )
321
+ self ._theta_label1_position = (
322
+ mtransforms .Affine2D ().translate (0.0 , 1.1 ))
320
323
self ._xaxis_text1_transform = (
321
324
self ._theta_label1_position +
322
325
self ._xaxis_transform )
323
- self ._theta_label2_position = Affine2D ().translate (0.0 , 1.0 / 1.1 )
326
+ self ._theta_label2_position = (
327
+ mtransforms .Affine2D ().translate (0.0 , 1.0 / 1.1 ))
324
328
self ._xaxis_text2_transform = (
325
329
self ._theta_label2_position +
326
330
self ._xaxis_transform )
@@ -329,14 +333,14 @@ def _set_lim_and_transforms(self):
329
333
# axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
330
334
# 2pi.
331
335
self ._yaxis_transform = (
332
- Affine2D ().scale (np .pi * 2.0 , 1.0 ) +
336
+ mtransforms . Affine2D ().scale (np .pi * 2.0 , 1.0 ) +
333
337
self .transData )
334
338
# The r-axis labels are put at an angle and padded in the r-direction
335
- self ._r_label_position = ScaledTranslation (
336
- self ._default_rlabel_position , 0.0 , Affine2D ())
339
+ self ._r_label_position = mtransforms . ScaledTranslation (
340
+ self ._default_rlabel_position , 0.0 , mtransforms . Affine2D ())
337
341
self ._yaxis_text_transform = (
338
342
self ._r_label_position +
339
- Affine2D ().scale (1.0 / 360.0 , 1.0 ) +
343
+ mtransforms . Affine2D ().scale (1.0 / 360.0 , 1.0 ) +
340
344
self ._yaxis_transform
341
345
)
342
346
@@ -381,7 +385,7 @@ def get_yaxis_text2_transform(self, pad):
381
385
return self ._yaxis_text_transform , 'bottom' , 'right'
382
386
383
387
def _gen_axes_patch (self ):
384
- return Circle ((0.5 , 0.5 ), 0.5 )
388
+ return mpatches . Circle ((0.5 , 0.5 ), 0.5 )
385
389
386
390
def _gen_axes_spines (self ):
387
391
return {'polar' :mspines .Spine .circular_spine (self ,
@@ -531,7 +535,7 @@ def set_thetagrids(self, angles, labels=None, frac=None, fmt=None,
531
535
if labels is not None :
532
536
self .set_xticklabels (labels )
533
537
elif fmt is not None :
534
- self .xaxis .set_major_formatter (FormatStrFormatter (fmt ))
538
+ self .xaxis .set_major_formatter (mticker . FormatStrFormatter (fmt ))
535
539
if frac is not None :
536
540
self ._theta_label1_position .clear ().translate (0.0 , frac )
537
541
self ._theta_label2_position .clear ().translate (0.0 , 1.0 / frac )
@@ -571,7 +575,7 @@ def set_rgrids(self, radii, labels=None, angle=None, fmt=None,
571
575
if labels is not None :
572
576
self .set_yticklabels (labels )
573
577
elif fmt is not None :
574
- self .yaxis .set_major_formatter (FormatStrFormatter (fmt ))
578
+ self .yaxis .set_major_formatter (mticker . FormatStrFormatter (fmt ))
575
579
if angle is None :
576
580
angle = self .get_rlabel_position ()
577
581
self .set_rlabel_position (angle )
0 commit comments