Skip to content

Commit 4046e9f

Browse files
MNT/DOC: Deprecate anchor in Axes3D.set_aspect
1 parent 40a47e5 commit 4046e9f

File tree

2 files changed

+44
-26
lines changed

2 files changed

+44
-26
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _transformed_cube(self, vals):
244244
(minx, maxy, maxz)]
245245
return proj3d._proj_points(xyzs, self.M)
246246

247-
def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
247+
def set_aspect(self, aspect, adjustable=None, anchor=None):
248248
"""
249249
Set the aspect ratios.
250250
@@ -263,39 +263,26 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
263263
'equalyz' adapt the y and z axes to have equal aspect ratios.
264264
========= ==================================================
265265
266-
adjustable : None or {'box', 'datalim'}, optional
267-
If not *None*, this defines which parameter will be adjusted to
268-
meet the required aspect. See `.set_adjustable` for further
269-
details.
270-
271-
anchor : None or str or 2-tuple of float, optional
272-
If not *None*, this defines where the Axes will be drawn if there
273-
is extra space due to aspect constraints. The most common way to
274-
specify the anchor are abbreviations of cardinal directions:
275-
276-
===== =====================
277-
value description
278-
===== =====================
279-
'C' centered
280-
'SW' lower left corner
281-
'S' middle of bottom edge
282-
'SE' lower right corner
283-
etc.
284-
===== =====================
266+
``adjustable`` : {'box', 'datalim'}, default: 'box'
267+
` Which parameter to adjust to meet the aspect ratio.
268+
- 'box': Change the physical dimensions of the axes bounding box.
269+
- 'datalim': Change the x, y, or z data limits.
285270
286-
See `~.Axes.set_anchor` for further details.
287-
288-
share : bool, default: False
289-
If ``True``, apply the settings to all shared Axes.
271+
``anchor`` : None or str or 2-tuple of float, optional
272+
.. deprecated:: 3.11
273+
The *anchor* parameter is not used for 3D axes and will be
274+
removed in a future version. It is ignored.
290275
291276
See Also
292277
--------
293278
mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect
294279
"""
280+
if anchor is not None:
281+
_api.warn_deprecated("3.11", name="anchor", removal="3.13")
295282
_api.check_in_list(('auto', 'equal', 'equalxy', 'equalyz', 'equalxz'),
296283
aspect=aspect)
297-
super().set_aspect(
298-
aspect='auto', adjustable=adjustable, anchor=anchor, share=share)
284+
if adjustable is not None:
285+
self.set_adjustable(adjustable)
299286
self._aspect = aspect
300287

301288
if aspect in ('equal', 'equalxy', 'equalxz', 'equalyz'):

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from matplotlib.patches import Circle, PathPatch
1818
from matplotlib.path import Path
1919
from matplotlib.text import Text
20+
from matplotlib import _api
21+
import warnings
2022

2123
import matplotlib.pyplot as plt
2224
import numpy as np
@@ -2689,3 +2691,32 @@ def test_ndarray_color_kwargs_value_error():
26892691
ax = fig.add_subplot(111, projection='3d')
26902692
ax.scatter(1, 0, 0, color=np.array([0, 0, 0, 1]))
26912693
fig.canvas.draw()
2694+
2695+
2696+
def test_axes3d_set_aspect_arguments():
2697+
"""
2698+
Test argument handling for Axes3D.set_aspect.
2699+
2700+
- Verifies that the `anchor` parameter correctly raises a
2701+
DeprecationWarning.
2702+
- Verifies that calling without `anchor` does not warn.
2703+
- Verifies that the `adjustable` parameter is passed through correctly.
2704+
"""
2705+
fig = plt.figure()
2706+
ax = fig.add_subplot(projection='3d')
2707+
2708+
# Test that providing the `anchor` parameter raises a deprecation warning.
2709+
with pytest.warns(_api.MatplotlibDeprecationWarning, match="anchor"):
2710+
ax.set_aspect('equal', anchor='C')
2711+
2712+
# Test that a call without `anchor` does not raise any warnings.
2713+
with warnings.catch_warnings(record=True) as record:
2714+
warnings.simplefilter("always")
2715+
ax.set_aspect('equal')
2716+
# Assert that the list of caught warnings is empty.
2717+
assert len(record) == 0
2718+
2719+
# Test that the `adjustable` parameter is correctly processed to satisfy
2720+
# code coverage.
2721+
ax.set_aspect('equal', adjustable='box')
2722+
assert ax.get_adjustable() == 'box'

0 commit comments

Comments
 (0)