9
9
import matplotlib .axis as maxis
10
10
from matplotlib import cbook
11
11
from matplotlib import docstring
12
+ import matplotlib .markers as mmarkers
12
13
import matplotlib .patches as mpatches
13
14
import matplotlib .path as mpath
14
15
from matplotlib import rcParams
@@ -240,6 +241,58 @@ def zoom(self, direction):
240
241
return self .base .zoom (direction )
241
242
242
243
244
+ class ThetaTick (maxis .XTick ):
245
+ """
246
+ A theta-axis tick.
247
+
248
+ This subclass of `XTick` provides angular ticks with some small
249
+ modification to their re-positioning such that ticks are rotated based on
250
+ tick location. This results in ticks that are correctly perpendicular to
251
+ the arc spine. Labels are also rotated to be parallel to the spine.
252
+ """
253
+ def _get_text1 (self ):
254
+ t = maxis .XTick ._get_text1 (self )
255
+ t .set_rotation_mode ('anchor' )
256
+ return t
257
+
258
+ def _get_text2 (self ):
259
+ t = maxis .XTick ._get_text2 (self )
260
+ t .set_rotation_mode ('anchor' )
261
+ return t
262
+
263
+ def update_position (self , loc ):
264
+ maxis .XTick .update_position (self , loc )
265
+ axes = self .axes
266
+ angle = (loc * axes .get_theta_direction () +
267
+ axes .get_theta_offset () - np .pi / 2 )
268
+
269
+ if self .tick1On :
270
+ marker = self .tick1line .get_marker ()
271
+ if marker in (mmarkers .TICKUP , '|' ):
272
+ trans = mtransforms .Affine2D ().scale (1.0 , 1.0 ).rotate (angle )
273
+ elif marker == mmarkers .TICKDOWN :
274
+ trans = mtransforms .Affine2D ().scale (1.0 , - 1.0 ).rotate (angle )
275
+ else :
276
+ # Don't modify custom tick line markers.
277
+ trans = self .tick1line ._marker ._transform
278
+ self .tick1line ._marker ._transform = trans
279
+ if self .tick2On :
280
+ marker = self .tick2line .get_marker ()
281
+ if marker in (mmarkers .TICKUP , '|' ):
282
+ trans = mtransforms .Affine2D ().scale (1.0 , 1.0 ).rotate (angle )
283
+ elif marker == mmarkers .TICKDOWN :
284
+ trans = mtransforms .Affine2D ().scale (1.0 , - 1.0 ).rotate (angle )
285
+ else :
286
+ # Don't modify custom tick line markers.
287
+ trans = self .tick2line ._marker ._transform
288
+ self .tick2line ._marker ._transform = trans
289
+
290
+ if self .label1On :
291
+ self .label1 .set_rotation (np .rad2deg (angle ) + self ._labelrotation )
292
+ if self .label2On :
293
+ self .label2 .set_rotation (np .rad2deg (angle ) + self ._labelrotation )
294
+
295
+
243
296
class ThetaAxis (maxis .XAxis ):
244
297
"""
245
298
A theta Axis.
@@ -255,7 +308,7 @@ def _get_tick(self, major):
255
308
tick_kw = self ._major_tick_kw
256
309
else :
257
310
tick_kw = self ._minor_tick_kw
258
- return maxis . XTick (self .axes , 0 , '' , major = major , ** tick_kw )
311
+ return ThetaTick (self .axes , 0 , '' , major = major , ** tick_kw )
259
312
260
313
def _wrap_locator_formatter (self ):
261
314
self .set_major_locator (ThetaLocator (self .get_major_locator ()))
@@ -587,10 +640,10 @@ def get_xaxis_transform(self, which='grid'):
587
640
return self ._xaxis_transform
588
641
589
642
def get_xaxis_text1_transform (self , pad ):
590
- return self ._xaxis_text1_transform , 'center ' , 'center'
643
+ return self ._xaxis_text1_transform , 'bottom ' , 'center'
591
644
592
645
def get_xaxis_text2_transform (self , pad ):
593
- return self ._xaxis_text2_transform , 'center ' , 'center'
646
+ return self ._xaxis_text2_transform , 'top ' , 'center'
594
647
595
648
def get_yaxis_transform (self , which = 'grid' ):
596
649
if which in ('tick1' , 'tick2' ):
0 commit comments