Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 720a16d

Browse filesBrowse files
committed
MNT: Use transforms for polar direction&offset.
This enables some nicer automatic invalidation for later work.
1 parent 67e6f5a commit 720a16d
Copy full SHA for 720a16d

File tree

Expand file treeCollapse file tree

10 files changed

+3468
-3130
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+3468
-3130
lines changed

‎lib/matplotlib/projections/polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+35-18Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def __init__(self, *args, **kwargs):
244244
self.resolution = kwargs.pop('resolution', 1)
245245
self._default_theta_offset = kwargs.pop('theta_offset', 0)
246246
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))
248249

249250
if self.resolution not in (None, 1):
250251
warnings.warn(
@@ -297,6 +298,20 @@ def _set_lim_and_transforms(self):
297298
self._originViewLim = mtransforms.LockedBbox(self.viewLim)
298299
self._originViewLim._parents[id(self)] = self # Hack!
299300

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+
300315
self.transAxes = mtransforms.BboxTransformTo(self.bbox)
301316

302317
# Transforms the x and y axis separately by a scale factor
@@ -312,10 +327,10 @@ def _set_lim_and_transforms(self):
312327

313328
# A (possibly non-linear) projection on the (already scaled)
314329
# data. This one is aware of rmin
315-
self.transProjection = self.PolarTransform(self)
330+
self.transProjection = self.PolarTransform()
316331

317332
# This one is not aware of rmin
318-
self.transPureProjection = self.PolarTransform(self, use_rmin=False)
333+
self.transPureProjection = self.PolarTransform(use_rmin=False)
319334

320335
# An affine transformation on the data, generally to limit the
321336
# range of the axes
@@ -324,14 +339,15 @@ def _set_lim_and_transforms(self):
324339

325340
# The complete data transformation stack -- from data all the
326341
# 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 + \
329344
(self.transProjectionAffine + self.transAxes)
330345

331346
# This is the transform for theta-axis ticks. It is
332347
# equivalent to transData, except it always puts r == 1.0 at
333348
# the edge of the axis circle.
334349
self._xaxis_transform = (
350+
self.transShift +
335351
self.transPureProjection +
336352
self.PolarAffine(mtransforms.IdentityTransform(),
337353
mtransforms.Bbox.unit()) +
@@ -352,16 +368,13 @@ def _set_lim_and_transforms(self):
352368
# axis so the gridlines from 0.0 to 1.0, now go from 0.0 to
353369
# 2pi.
354370
self._yaxis_transform = (
371+
self.transShift +
355372
mtransforms.Affine2D().scale(np.pi * 2.0, 1.0) +
356373
self.transData)
357374
# The r-axis labels are put at an angle and padded in the r-direction
358375
self._r_label_position = mtransforms.ScaledTranslation(
359376
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
365378

366379
def get_xaxis_transform(self,which='grid'):
367380
if which not in ['tick1','tick2','grid']:
@@ -438,13 +451,15 @@ def set_theta_offset(self, offset):
438451
"""
439452
Set the offset for the location of 0 in radians.
440453
"""
441-
self._theta_offset = offset
454+
mtx = self._theta_offset.get_matrix()
455+
mtx[0, 2] = offset
456+
self._theta_offset.invalidate()
442457

443458
def get_theta_offset(self):
444459
"""
445460
Get the offset for the location of 0 in radians.
446461
"""
447-
return self._theta_offset
462+
return self._theta_offset.get_matrix()[0, 2]
448463

449464
def set_theta_zero_location(self, loc):
450465
"""
@@ -474,14 +489,16 @@ def set_theta_direction(self, direction):
474489
counterclockwise, anticlockwise, 1:
475490
Theta increases in the counterclockwise direction
476491
"""
492+
mtx = self._direction.get_matrix()
477493
if direction in ('clockwise',):
478-
self._direction = -1
494+
mtx[0, 0] = -1
479495
elif direction in ('counterclockwise', 'anticlockwise'):
480-
self._direction = 1
496+
mtx[0, 0] = 1
481497
elif direction in (1, -1):
482-
self._direction = direction
498+
mtx[0, 0] = direction
483499
else:
484500
raise ValueError("direction must be 1, -1, clockwise or counterclockwise")
501+
self._direction.invalidate()
485502

486503
def get_theta_direction(self):
487504
"""
@@ -493,7 +510,7 @@ def get_theta_direction(self):
493510
1:
494511
Theta increases in the counterclockwise direction
495512
"""
496-
return self._direction
513+
return self._direction.get_matrix()[0, 0]
497514

498515
def set_rmax(self, rmax):
499516
self.viewLim.y1 = rmax
@@ -527,7 +544,7 @@ def get_rlabel_position(self):
527544
float
528545
The theta position of the radius labels in degrees.
529546
"""
530-
return self._r_label_position.to_values()[4]
547+
return np.rad2deg(self._r_label_position.to_values()[4])
531548

532549
def set_rlabel_position(self, value):
533550
"""Updates the theta position of the radius labels.
@@ -537,7 +554,7 @@ def set_rlabel_position(self, value):
537554
value : number
538555
The angular position of the radius labels in degrees.
539556
"""
540-
self._r_label_position._xt = value
557+
self._r_label_position._xt = np.deg2rad(value)
541558
self._r_label_position.invalidate()
542559

543560
def set_yscale(self, *args, **kwargs):
Binary file not shown.
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.