Skip to content

MNT/DOC: Deprecate anchor in Axes3D.set_aspect #30408

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
39 changes: 13 additions & 26 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def _transformed_cube(self, vals):
(minx, maxy, maxz)]
return proj3d._proj_points(xyzs, self.M)

def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
def set_aspect(self, aspect, adjustable=None, anchor=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete share?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! I removed the share parameter because it was only being passed to the super().set_aspect() call.
During local testing, I found that the super() call was causing an ImageComparisonFailure in the existing test_aspects test. Based on the original issue's suggestion and that test failure, I removed the super() call entirely. Since share was no longer being used anywhere inside the method, I removed it from the signature and docstring as well to clean up the unused code.
Please let me know if you think it should be handled differently

"""
Set the aspect ratios.

Expand All @@ -263,39 +263,26 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
'equalyz' adapt the y and z axes to have equal aspect ratios.
========= ==================================================

adjustable : None or {'box', 'datalim'}, optional
If not *None*, this defines which parameter will be adjusted to
meet the required aspect. See `.set_adjustable` for further
details.

anchor : None or str or 2-tuple of float, optional
If not *None*, this defines where the Axes will be drawn if there
is extra space due to aspect constraints. The most common way to
specify the anchor are abbreviations of cardinal directions:

===== =====================
value description
===== =====================
'C' centered
'SW' lower left corner
'S' middle of bottom edge
'SE' lower right corner
etc.
===== =====================
``adjustable`` : {'box', 'datalim'}, default: 'box'
` Which parameter to adjust to meet the aspect ratio.
- 'box': Change the physical dimensions of the axes bounding box.
- 'datalim': Change the x, y, or z data limits.

See `~.Axes.set_anchor` for further details.

share : bool, default: False
If ``True``, apply the settings to all shared Axes.
``anchor`` : None or str or 2-tuple of float, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed to code style?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the double backticks here for the same reason as for the adjustable parameter: to resolve a documentation build failure that was happening in the CI.

.. deprecated:: 3.11
The *anchor* parameter is not used for 3D axes and will be
removed in a future version. It is ignored.

See Also
--------
mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect
"""
if anchor is not None:
_api.warn_deprecated("3.11", name="anchor", removal="3.13")
_api.check_in_list(('auto', 'equal', 'equalxy', 'equalyz', 'equalxz'),
aspect=aspect)
super().set_aspect(
aspect='auto', adjustable=adjustable, anchor=anchor, share=share)
if adjustable is not None:
self.set_adjustable(adjustable)
self._aspect = aspect

if aspect in ('equal', 'equalxy', 'equalxz', 'equalyz'):
Expand Down
31 changes: 31 additions & 0 deletions lib/mpl_toolkits/mplot3d/tests/test_axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from matplotlib.patches import Circle, PathPatch
from matplotlib.path import Path
from matplotlib.text import Text
from matplotlib import _api
import warnings

import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -2689,3 +2691,32 @@ def test_ndarray_color_kwargs_value_error():
ax = fig.add_subplot(111, projection='3d')
ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1]))
fig.canvas.draw()


def test_axes3d_set_aspect_arguments():
"""
Test argument handling for Axes3D.set_aspect.

- Verifies that the `anchor` parameter correctly raises a
DeprecationWarning.
- Verifies that calling without `anchor` does not warn.
- Verifies that the `adjustable` parameter is passed through correctly.
"""
fig = plt.figure()
ax = fig.add_subplot(projection='3d')

# Test that providing the `anchor` parameter raises a deprecation warning.
with pytest.warns(_api.MatplotlibDeprecationWarning, match="anchor"):
ax.set_aspect('equal', anchor='C')

# Test that a call without `anchor` does not raise any warnings.
with warnings.catch_warnings(record=True) as record:
warnings.simplefilter("always")
ax.set_aspect('equal')
# Assert that the list of caught warnings is empty.
assert len(record) == 0

# Test that the `adjustable` parameter is correctly processed to satisfy
# code coverage.
ax.set_aspect('equal', adjustable='box')
assert ax.get_adjustable() == 'box'
Loading