@@ -244,7 +244,8 @@ def __init__(self, *args, **kwargs):
244
244
self .resolution = kwargs .pop ('resolution' , 1 )
245
245
self ._default_theta_offset = kwargs .pop ('theta_offset' , 0 )
246
246
self ._default_theta_direction = kwargs .pop ('theta_direction' , 1 )
247
- self ._default_rlabel_position = kwargs .pop ('rlabel_position' , 22.5 )
247
+ self ._default_rlabel_position = np .deg2rad (
248
+ kwargs .pop ('rlabel_position' , 22.5 ))
248
249
249
250
if self .resolution not in (None , 1 ):
250
251
warnings .warn (
@@ -297,6 +298,20 @@ def _set_lim_and_transforms(self):
297
298
self ._originViewLim = mtransforms .LockedBbox (self .viewLim )
298
299
self ._originViewLim ._parents [id (self )] = self # Hack!
299
300
301
+ # Handle angular offset and direction.
302
+ self ._direction = mtransforms .Affine2D () \
303
+ .scale (self ._default_theta_direction , 1.0 )
304
+ self ._theta_offset = mtransforms .Affine2D () \
305
+ .translate (self ._default_theta_offset , 0.0 )
306
+ self .transShift = mtransforms .composite_transform_factory (
307
+ self ._direction ,
308
+ self ._theta_offset )
309
+ # A view limit shifted to the correction location after accounting for
310
+ # orientation and offset.
311
+ self ._shiftedViewLim = mtransforms .TransformedBbox (self .viewLim ,
312
+ self .transShift )
313
+ self ._shiftedViewLim ._parents [id (self )] = self
314
+
300
315
self .transAxes = mtransforms .BboxTransformTo (self .bbox )
301
316
302
317
# Transforms the x and y axis separately by a scale factor
@@ -312,10 +327,10 @@ def _set_lim_and_transforms(self):
312
327
313
328
# A (possibly non-linear) projection on the (already scaled)
314
329
# data. This one is aware of rmin
315
- self .transProjection = self .PolarTransform (self )
330
+ self .transProjection = self .PolarTransform ()
316
331
317
332
# This one is not aware of rmin
318
- self .transPureProjection = self .PolarTransform (self , use_rmin = False )
333
+ self .transPureProjection = self .PolarTransform (use_rmin = False )
319
334
320
335
# An affine transformation on the data, generally to limit the
321
336
# range of the axes
@@ -324,14 +339,15 @@ def _set_lim_and_transforms(self):
324
339
325
340
# The complete data transformation stack -- from data all the
326
341
# way to display coordinates
327
- self .transData = self .transScale + self .transOffset + \
328
- self .transPureProjection + \
342
+ self .transData = self .transScale + self .transShift + \
343
+ self .transOffset + self . transProjection + \
329
344
(self .transProjectionAffine + self .transAxes )
330
345
331
346
# This is the transform for theta-axis ticks. It is
332
347
# equivalent to transData, except it always puts r == 1.0 at
333
348
# the edge of the axis circle.
334
349
self ._xaxis_transform = (
350
+ self .transShift +
335
351
self .transPureProjection +
336
352
self .PolarAffine (mtransforms .IdentityTransform (),
337
353
mtransforms .Bbox .unit ()) +
@@ -352,16 +368,13 @@ def _set_lim_and_transforms(self):
352
368
# axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
353
369
# 2pi.
354
370
self ._yaxis_transform = (
371
+ self .transShift +
355
372
mtransforms .Affine2D ().scale (np .pi * 2.0 , 1.0 ) +
356
373
self .transData )
357
374
# The r-axis labels are put at an angle and padded in the r-direction
358
375
self ._r_label_position = mtransforms .ScaledTranslation (
359
376
self ._default_rlabel_position , 0.0 , mtransforms .Affine2D ())
360
- self ._yaxis_text_transform = (
361
- self ._r_label_position +
362
- mtransforms .Affine2D ().scale (1.0 / 360.0 , 1.0 ) +
363
- self ._yaxis_transform
364
- )
377
+ self ._yaxis_text_transform = self ._r_label_position + self .transData
365
378
366
379
def get_xaxis_transform (self ,which = 'grid' ):
367
380
if which not in ['tick1' ,'tick2' ,'grid' ]:
@@ -438,13 +451,15 @@ def set_theta_offset(self, offset):
438
451
"""
439
452
Set the offset for the location of 0 in radians.
440
453
"""
441
- self ._theta_offset = offset
454
+ mtx = self ._theta_offset .get_matrix ()
455
+ mtx [0 , 2 ] = offset
456
+ self ._theta_offset .invalidate ()
442
457
443
458
def get_theta_offset (self ):
444
459
"""
445
460
Get the offset for the location of 0 in radians.
446
461
"""
447
- return self ._theta_offset
462
+ return self ._theta_offset . get_matrix ()[ 0 , 2 ]
448
463
449
464
def set_theta_zero_location (self , loc ):
450
465
"""
@@ -474,14 +489,16 @@ def set_theta_direction(self, direction):
474
489
counterclockwise, anticlockwise, 1:
475
490
Theta increases in the counterclockwise direction
476
491
"""
492
+ mtx = self ._direction .get_matrix ()
477
493
if direction in ('clockwise' ,):
478
- self . _direction = - 1
494
+ mtx [ 0 , 0 ] = - 1
479
495
elif direction in ('counterclockwise' , 'anticlockwise' ):
480
- self . _direction = 1
496
+ mtx [ 0 , 0 ] = 1
481
497
elif direction in (1 , - 1 ):
482
- self . _direction = direction
498
+ mtx [ 0 , 0 ] = direction
483
499
else :
484
500
raise ValueError ("direction must be 1, -1, clockwise or counterclockwise" )
501
+ self ._direction .invalidate ()
485
502
486
503
def get_theta_direction (self ):
487
504
"""
@@ -493,7 +510,7 @@ def get_theta_direction(self):
493
510
1:
494
511
Theta increases in the counterclockwise direction
495
512
"""
496
- return self ._direction
513
+ return self ._direction . get_matrix ()[ 0 , 0 ]
497
514
498
515
def set_rmax (self , rmax ):
499
516
self .viewLim .y1 = rmax
@@ -527,7 +544,7 @@ def get_rlabel_position(self):
527
544
float
528
545
The theta position of the radius labels in degrees.
529
546
"""
530
- return self ._r_label_position .to_values ()[4 ]
547
+ return np . rad2deg ( self ._r_label_position .to_values ()[4 ])
531
548
532
549
def set_rlabel_position (self , value ):
533
550
"""Updates the theta position of the radius labels.
@@ -537,7 +554,7 @@ def set_rlabel_position(self, value):
537
554
value : number
538
555
The angular position of the radius labels in degrees.
539
556
"""
540
- self ._r_label_position ._xt = value
557
+ self ._r_label_position ._xt = np . deg2rad ( value )
541
558
self ._r_label_position .invalidate ()
542
559
543
560
def set_yscale (self , * args , ** kwargs ):
0 commit comments