Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Remove apply_theta_transforms argument#30004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dstansby wants to merge3 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromdstansby:no-apply-theta-transforms
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletionsdoc/api/next_api_changes/removals/30004-DS.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
``apply_theta_transforms`` option in ``PolarTransform``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Applying theta transforms in `~matplotlib.projections.polar.PolarTransform` and
`~matplotlib.projections.polar.InvertedPolarTransform` has been removed, and
the ``apply_theta_transforms`` keyword argument removed from both classes.

If you need to retain the behaviour where theta values
are transformed, chain the ``PolarTransform`` with a `~matplotlib.transforms.Affine2D`
transform that performs the theta shift and/or sign shift.
2 changes: 1 addition & 1 deletiongalleries/examples/axisartist/demo_axis_direction.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ def setup_axes(fig, rect):
grid_helper = GridHelperCurveLinear(
(
Affine2D().scale(np.pi/180., 1.) +
PolarAxes.PolarTransform(apply_theta_transforms=False)
PolarAxes.PolarTransform()
),
extreme_finder=angle_helper.ExtremeFinderCycle(
20, 20,
Expand Down
3 changes: 1 addition & 2 deletionsgalleries/examples/axisartist/demo_curvelinear_grid.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,8 +54,7 @@ def curvelinear_test2(fig):

# PolarAxes.PolarTransform takes radian. However, we want our coordinate
# system in degree
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = Affine2D().scale(np.pi/180, 1) + PolarAxes.PolarTransform()
# Polar projection, which involves cycle, and also has limits in
# its coordinates, needs a special method to find the extremes
# (min, max of the coordinate within the view).
Expand Down
5 changes: 2 additions & 3 deletionsgalleries/examples/axisartist/demo_floating_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -54,7 +54,7 @@ def setup_axes2(fig, rect):
With custom locator and formatter.
Note that the extreme values are swapped.
"""
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
tr = PolarAxes.PolarTransform()

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

tr = tr_rotate + tr_scale + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = tr_rotate + tr_scale + PolarAxes.PolarTransform()

grid_locator1 = angle_helper.LocatorHMS(4)
tick_formatter1 = angle_helper.FormatterHMS()
Expand Down
3 changes: 1 addition & 2 deletionsgalleries/examples/axisartist/demo_floating_axis.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,8 +22,7 @@
def curvelinear_test2(fig):
"""Polar projection, but in a rectangular box."""
# see demo_curvelinear_grid.py for details
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform(
apply_theta_transforms=False)
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()

extreme_finder = angle_helper.ExtremeFinderCycle(20,
20,
Expand Down
3 changes: 1 addition & 2 deletionsgalleries/examples/axisartist/simple_axis_pad.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,8 +21,7 @@ def setup_axes(fig, rect):
"""Polar projection, but in a rectangular box."""

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

extreme_finder = angle_helper.ExtremeFinderCycle(20, 20,
lon_cycle=360,
Expand Down
55 changes: 7 additions & 48 deletionslib/matplotlib/projections/polar.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,20 +15,6 @@
from matplotlib.spines import Spine


def _apply_theta_transforms_warn():
_api.warn_deprecated(
"3.9",
message=(
"Passing `apply_theta_transforms=True` (the default) "
"is deprecated since Matplotlib %(since)s. "
"Support for this will be removed in Matplotlib in %(removal)s. "
"To prevent this warning, set `apply_theta_transforms=False`, "
"and make sure to shift theta values before being passed to "
"this transform."
)
)


class PolarTransform(mtransforms.Transform):
r"""
The base polar transform.
Expand All@@ -48,8 +34,7 @@

input_dims = output_dims = 2

def __init__(self, axis=None, use_rmin=True, *,
apply_theta_transforms=True, scale_transform=None):
def __init__(self, axis=None, use_rmin=True, *, scale_transform=None):
"""
Parameters
----------
Expand All@@ -64,15 +49,12 @@
super().__init__()
self._axis = axis
self._use_rmin = use_rmin
self._apply_theta_transforms = apply_theta_transforms
self._scale_transform = scale_transform
if apply_theta_transforms:
_apply_theta_transforms_warn()

__str__ = mtransforms._make_str_method(
"_axis",
use_rmin="_use_rmin",
apply_theta_transforms="_apply_theta_transforms")
use_rmin="_use_rmin"
)

def _get_rorigin(self):
# Get lower r limit after being scaled by the radial scale transform
Expand All@@ -82,11 +64,6 @@
def transform_non_affine(self, values):
# docstring inherited
theta, r = np.transpose(values)
# PolarAxes does not use the theta transforms here, but apply them for
# backwards-compatibility if not being used by it.
if self._apply_theta_transforms and self._axis is not None:
theta *= self._axis.get_theta_direction()
theta += self._axis.get_theta_offset()
if self._use_rmin and self._axis is not None:
r = (r - self._get_rorigin()) * self._axis.get_rsign()
r = np.where(r >= 0, r, np.nan)
Expand DownExpand Up@@ -148,10 +125,7 @@

def inverted(self):
# docstring inherited
return PolarAxes.InvertedPolarTransform(
self._axis, self._use_rmin,
apply_theta_transforms=self._apply_theta_transforms
)
return PolarAxes.InvertedPolarTransform(self._axis, self._use_rmin)


class PolarAffine(mtransforms.Affine2DBase):
Expand DownExpand Up@@ -209,8 +183,7 @@
"""
input_dims = output_dims = 2

def __init__(self, axis=None, use_rmin=True,
*, apply_theta_transforms=True):
def __init__(self, axis=None, use_rmin=True):
"""
Parameters
----------
Expand All@@ -225,37 +198,24 @@
super().__init__()
self._axis = axis
self._use_rmin = use_rmin
self._apply_theta_transforms = apply_theta_transforms
if apply_theta_transforms:
_apply_theta_transforms_warn()

__str__ = mtransforms._make_str_method(
"_axis",
use_rmin="_use_rmin",
apply_theta_transforms="_apply_theta_transforms")
use_rmin="_use_rmin")

def transform_non_affine(self, values):
# docstring inherited
x, y = values.T
r = np.hypot(x, y)
theta = (np.arctan2(y, x) + 2 * np.pi) % (2 * np.pi)
# PolarAxes does not use the theta transforms here, but apply them for
# backwards-compatibility if not being used by it.
if self._apply_theta_transforms and self._axis is not None:
theta -= self._axis.get_theta_offset()
theta *= self._axis.get_theta_direction()
theta %= 2 * np.pi
if self._use_rmin and self._axis is not None:
r += self._axis.get_rorigin()
r *= self._axis.get_rsign()
return np.column_stack([theta, r])

def inverted(self):
# docstring inherited
return PolarAxes.PolarTransform(
self._axis, self._use_rmin,
apply_theta_transforms=self._apply_theta_transforms
)
return PolarAxes.PolarTransform(self._axis, self._use_rmin)

Check warning on line 218 in lib/matplotlib/projections/polar.py

View check run for this annotation

Codecov/ codecov/patch

lib/matplotlib/projections/polar.py#L218

Added line #L218 was not covered by tests


class ThetaFormatter(mticker.Formatter):
Expand DownExpand Up@@ -895,7 +855,6 @@
# data. This one is aware of rmin
self.transProjection = self.PolarTransform(
self,
apply_theta_transforms=False,
scale_transform=self.transScale
)
# Add dependency on rorigin.
Expand Down
3 changes: 0 additions & 3 deletionslib/matplotlib/projections/polar.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,7 +18,6 @@ class PolarTransform(mtransforms.Transform):
axis: PolarAxes | None = ...,
use_rmin: bool = ...,
*,
apply_theta_transforms: bool = ...,
scale_transform: mtransforms.Transform | None = ...,
) -> None: ...
def inverted(self) -> InvertedPolarTransform: ...
Expand All@@ -35,8 +34,6 @@ class InvertedPolarTransform(mtransforms.Transform):
self,
axis: PolarAxes | None = ...,
use_rmin: bool = ...,
*,
apply_theta_transforms: bool = ...,
) -> None: ...
def inverted(self) -> PolarTransform: ...

Expand Down
3 changes: 1 addition & 2 deletionslib/matplotlib/tests/test_transforms.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -891,8 +891,7 @@ def test_str_transform():
Affine2D().scale(1.0))),
PolarTransform(
PolarAxes(0.125,0.1;0.775x0.8),
use_rmin=True,
apply_theta_transforms=False)),
use_rmin=True)),
CompositeGenericTransform(
CompositeGenericTransform(
PolarAffine(
Expand Down
5 changes: 2 additions & 3 deletionslib/matplotlib/text.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1553,9 +1553,8 @@ def _get_xy_transform(self, renderer, coords):
return self.axes.transData
elif coords == 'polar':
from matplotlib.projections import PolarAxes
tr = PolarAxes.PolarTransform(apply_theta_transforms=False)
trans = tr + self.axes.transData
return trans
tr = PolarAxes.PolarTransform()
return PolarAxes.PolarTransform() + self.axes.transData

try:
bbox_name, unit = coords.split()
Expand Down
4 changes: 2 additions & 2 deletionslib/mpl_toolkits/axisartist/tests/test_floating_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@ def test_curvelinear3():
fig = plt.figure(figsize=(5, 5))

tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) +
mprojections.PolarAxes.PolarTransform(apply_theta_transforms=False))
mprojections.PolarAxes.PolarTransform())
grid_helper = GridHelperCurveLinear(
tr,
extremes=(0, 360, 10, 3),
Expand DownExpand Up@@ -75,7 +75,7 @@ def test_curvelinear4():
fig = plt.figure(figsize=(5, 5))

tr = (mtransforms.Affine2D().scale(np.pi / 180, 1) +
mprojections.PolarAxes.PolarTransform(apply_theta_transforms=False))
mprojections.PolarAxes.PolarTransform())
grid_helper = GridHelperCurveLinear(
tr,
extremes=(120, 30, 10, 0),
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -82,8 +82,7 @@ def test_polar_box():

# PolarAxes.PolarTransform takes radian. However, we want our coordinate
# system in degree
tr = (Affine2D().scale(np.pi / 180., 1.) +
PolarAxes.PolarTransform(apply_theta_transforms=False))
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()

# polar projection, which involves cycle, and also has limits in
# its coordinates, needs a special method to find the extremes
Expand DownExpand Up@@ -145,8 +144,7 @@ def test_axis_direction():

# PolarAxes.PolarTransform takes radian. However, we want our coordinate
# system in degree
tr = (Affine2D().scale(np.pi / 180., 1.) +
PolarAxes.PolarTransform(apply_theta_transforms=False))
tr = Affine2D().scale(np.pi / 180., 1.) + PolarAxes.PolarTransform()

# polar projection, which involves cycle, and also has limits in
# its coordinates, needs a special method to find the extremes
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp