Skip to content

Commit 8703dc5

Browse files
authored
Merge pull request #24834 from dstansby/_apply_theta_transforms
Deprecate apply_theta_transforms=True to PolarTransform
2 parents e5098e0 + ee48fb3 commit 8703dc5

File tree

12 files changed

+75
-26
lines changed

12 files changed

+75
-26
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Applying theta transforms in ``PolarTransform``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Applying theta transforms in `~matplotlib.projections.polar.PolarTransform`
4+
and `~matplotlib.projections.polar.InvertedPolarTransform`
5+
is deprecated, and will be removed in a future version of Matplotlib. This
6+
is currently the default behaviour when these transforms are used externally,
7+
but only takes affect when:
8+
9+
- An axis is associated with the transform.
10+
- The axis has a non-zero theta offset or has theta values increasing in
11+
a clockwise direction.
12+
13+
To silence this warning and adopt future behaviour,
14+
set ``apply_theta_transforms=False``. If you need to retain the behaviour
15+
where theta values are transformed, chain the ``PolarTransform`` with
16+
a `~matplotlib.transforms.Affine2D` transform that performs the theta shift
17+
and/or sign shift.

galleries/examples/axisartist/demo_axis_direction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def setup_axes(fig, rect):
2020
"""Polar projection, but in a rectangular box."""
2121
# see demo_curvelinear_grid.py for details
2222
grid_helper = GridHelperCurveLinear(
23-
Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(),
23+
(
24+
Affine2D().scale(np.pi/180., 1.) +
25+
PolarAxes.PolarTransform(apply_theta_transforms=False)
26+
),
2427
extreme_finder=angle_helper.ExtremeFinderCycle(
2528
20, 20,
2629
lon_cycle=360, lat_cycle=None,

galleries/examples/axisartist/demo_curvelinear_grid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def curvelinear_test2(fig):
5454

5555
# PolarAxes.PolarTransform takes radian. However, we want our coordinate
5656
# system in degree
57-
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform()
57+
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform(
58+
apply_theta_transforms=False)
5859
# Polar projection, which involves cycle, and also has limits in
5960
# its coordinates, needs a special method to find the extremes
6061
# (min, max of the coordinate within the view).

galleries/examples/axisartist/demo_floating_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def setup_axes2(fig, rect):
5454
With custom locator and formatter.
5555
Note that the extreme values are swapped.
5656
"""
57-
tr = PolarAxes.PolarTransform()
57+
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
5858

5959
pi = np.pi
6060
angle_ticks = [(0, r"$0$"),
@@ -99,7 +99,8 @@ def setup_axes3(fig, rect):
9999
# scale degree to radians
100100
tr_scale = Affine2D().scale(np.pi/180., 1.)
101101

102-
tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()
102+
tr = tr_rotate + tr_scale + PolarAxes.PolarTransform(
103+
apply_theta_transforms=False)
103104

104105
grid_locator1 = angle_helper.LocatorHMS(4)
105106
tick_formatter1 = angle_helper.FormatterHMS()

galleries/examples/axisartist/demo_floating_axis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
def curvelinear_test2(fig):
2323
"""Polar projection, but in a rectangular box."""
2424
# see demo_curvelinear_grid.py for details
25-
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()
25+
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform(
26+
apply_theta_transforms=False)
2627

2728
extreme_finder = angle_helper.ExtremeFinderCycle(20,
2829
20,

galleries/examples/axisartist/simple_axis_pad.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def setup_axes(fig, rect):
2121
"""Polar projection, but in a rectangular box."""
2222

2323
# see demo_curvelinear_grid.py for details
24-
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
24+
tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform(
25+
apply_theta_transforms=False)
2526

2627
extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
2728
lon_cycle=360,

lib/matplotlib/projections/polar.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
from matplotlib.spines import Spine
1616

1717

18+
def _apply_theta_transforms_warn():
19+
_api.warn_deprecated(
20+
"3.9",
21+
message=(
22+
"Passing `apply_theta_transforms=True` (the default) "
23+
"is deprecated since Matplotlib %(since)s. "
24+
"Support for this will be removed in Matplotlib %(removal)s. "
25+
"To prevent this warning, set `apply_theta_transforms=False`, "
26+
"and make sure to shift theta values before being passed to "
27+
"this transform."
28+
)
29+
)
30+
31+
1832
class PolarTransform(mtransforms.Transform):
1933
r"""
2034
The base polar transform.
@@ -34,8 +48,8 @@ class PolarTransform(mtransforms.Transform):
3448

3549
input_dims = output_dims = 2
3650

37-
def __init__(self, axis=None, use_rmin=True,
38-
_apply_theta_transforms=True, *, scale_transform=None):
51+
def __init__(self, axis=None, use_rmin=True, *,
52+
apply_theta_transforms=True, scale_transform=None):
3953
"""
4054
Parameters
4155
----------
@@ -50,13 +64,15 @@ def __init__(self, axis=None, use_rmin=True,
5064
super().__init__()
5165
self._axis = axis
5266
self._use_rmin = use_rmin
53-
self._apply_theta_transforms = _apply_theta_transforms
67+
self._apply_theta_transforms = apply_theta_transforms
5468
self._scale_transform = scale_transform
69+
if apply_theta_transforms:
70+
_apply_theta_transforms_warn()
5571

5672
__str__ = mtransforms._make_str_method(
5773
"_axis",
5874
use_rmin="_use_rmin",
59-
_apply_theta_transforms="_apply_theta_transforms")
75+
apply_theta_transforms="_apply_theta_transforms")
6076

6177
def _get_rorigin(self):
6278
# Get lower r limit after being scaled by the radial scale transform
@@ -133,8 +149,10 @@ def transform_path_non_affine(self, path):
133149

134150
def inverted(self):
135151
# docstring inherited
136-
return PolarAxes.InvertedPolarTransform(self._axis, self._use_rmin,
137-
self._apply_theta_transforms)
152+
return PolarAxes.InvertedPolarTransform(
153+
self._axis, self._use_rmin,
154+
apply_theta_transforms=self._apply_theta_transforms
155+
)
138156

139157

140158
class PolarAffine(mtransforms.Affine2DBase):
@@ -193,7 +211,7 @@ class InvertedPolarTransform(mtransforms.Transform):
193211
input_dims = output_dims = 2
194212

195213
def __init__(self, axis=None, use_rmin=True,
196-
_apply_theta_transforms=True):
214+
*, apply_theta_transforms=True):
197215
"""
198216
Parameters
199217
----------
@@ -208,12 +226,14 @@ def __init__(self, axis=None, use_rmin=True,
208226
super().__init__()
209227
self._axis = axis
210228
self._use_rmin = use_rmin
211-
self._apply_theta_transforms = _apply_theta_transforms
229+
self._apply_theta_transforms = apply_theta_transforms
230+
if apply_theta_transforms:
231+
_apply_theta_transforms_warn()
212232

213233
__str__ = mtransforms._make_str_method(
214234
"_axis",
215235
use_rmin="_use_rmin",
216-
_apply_theta_transforms="_apply_theta_transforms")
236+
apply_theta_transforms="_apply_theta_transforms")
217237

218238
@_api.rename_parameter("3.8", "xy", "values")
219239
def transform_non_affine(self, values):
@@ -234,8 +254,10 @@ def transform_non_affine(self, values):
234254

235255
def inverted(self):
236256
# docstring inherited
237-
return PolarAxes.PolarTransform(self._axis, self._use_rmin,
238-
self._apply_theta_transforms)
257+
return PolarAxes.PolarTransform(
258+
self._axis, self._use_rmin,
259+
apply_theta_transforms=self._apply_theta_transforms
260+
)
239261

240262

241263
class ThetaFormatter(mticker.Formatter):
@@ -879,7 +901,7 @@ def _set_lim_and_transforms(self):
879901
# data. This one is aware of rmin
880902
self.transProjection = self.PolarTransform(
881903
self,
882-
_apply_theta_transforms=False,
904+
apply_theta_transforms=False,
883905
scale_transform=self.transScale
884906
)
885907
# Add dependency on rorigin.

lib/matplotlib/projections/polar.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class PolarTransform(mtransforms.Transform):
1717
self,
1818
axis: PolarAxes | None = ...,
1919
use_rmin: bool = ...,
20-
_apply_theta_transforms: bool = ...,
2120
*,
21+
apply_theta_transforms: bool = ...,
2222
scale_transform: mtransforms.Transform | None = ...,
2323
) -> None: ...
2424
def inverted(self) -> InvertedPolarTransform: ...
@@ -35,7 +35,8 @@ class InvertedPolarTransform(mtransforms.Transform):
3535
self,
3636
axis: PolarAxes | None = ...,
3737
use_rmin: bool = ...,
38-
_apply_theta_transforms: bool = ...,
38+
*,
39+
apply_theta_transforms: bool = ...,
3940
) -> None: ...
4041
def inverted(self) -> PolarTransform: ...
4142

lib/matplotlib/tests/test_transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def test_str_transform():
859859
PolarTransform(
860860
PolarAxes(0.125,0.1;0.775x0.8),
861861
use_rmin=True,
862-
_apply_theta_transforms=False)),
862+
apply_theta_transforms=False)),
863863
CompositeGenericTransform(
864864
CompositeGenericTransform(
865865
PolarAffine(

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ def _get_xy_transform(self, renderer, coords):
14971497
return self.axes.transData
14981498
elif coords == 'polar':
14991499
from matplotlib.projections import PolarAxes
1500-
tr = PolarAxes.PolarTransform()
1500+
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
15011501
trans = tr + self.axes.transData
15021502
return trans
15031503

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy