Skip to content

Commit 1c0664c

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

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 24 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
@@ -264,38 +264,24 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
264264
========= ==================================================
265265
266266
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.
267+
This parameter is not used for 3D axes but is present for
268+
compatibility with 2D axes. It will be ignored.
270269
271270
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-
===== =====================
285-
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+
.. deprecated:: 3.11
272+
The `anchor` parameter is not used for 3D axes and will be
273+
removed in a future version. It is ignored.
290274
291275
See Also
292276
--------
293277
mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect
294278
"""
279+
if anchor is not None:
280+
_api.warn_deprecated("3.11", name="anchor", removal="3.13")
295281
_api.check_in_list(('auto', 'equal', 'equalxy', 'equalyz', 'equalxz'),
296282
aspect=aspect)
297-
super().set_aspect(
298-
aspect='auto', adjustable=adjustable, anchor=anchor, share=share)
283+
if adjustable is not None:
284+
self.set_adjustable(adjustable)
299285
self._aspect = aspect
300286

301287
if aspect in ('equal', 'equalxy', 'equalxz', 'equalyz'):
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
from matplotlib import _api
3+
import matplotlib.pyplot as plt
4+
import warnings
5+
6+
7+
def test_set_aspect_anchor_deprecation():
8+
"""Test that using the 'anchor' kwarg in set_aspect raises a warning."""
9+
fig = plt.figure()
10+
ax = fig.add_subplot(projection='3d')
11+
12+
# This should raise a warning
13+
with pytest.warns(_api.MatplotlibDeprecationWarning,
14+
match="anchor"):
15+
ax.set_aspect('equal', anchor='C')
16+
17+
# This should NOT raise a warning
18+
with warnings.catch_warnings(record=True) as record:
19+
warnings.simplefilter("always")
20+
ax.set_aspect('equal')
21+
# Filter out known, unrelated warnings if necessary
22+
# For now, let's assume no warnings should be present
23+
assert len(record) == 0

0 commit comments

Comments
 (0)