From 867802e97116767fe1999ec000c2dbdae57b758a Mon Sep 17 00:00:00 2001 From: Aaratrika-Shelly Date: Fri, 8 Aug 2025 19:18:31 +0000 Subject: [PATCH] MNT/DOC: Deprecate anchor in Axes3D.set_aspect --- lib/mpl_toolkits/mplot3d/axes3d.py | 35 +++++++------------ lib/mpl_toolkits/mplot3d/tests/test_axes3d.py | 31 ++++++++++++++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 9576b299ab72..b113735ee6ce 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -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): """ Set the aspect ratios. @@ -263,39 +263,30 @@ 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. + 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. 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. - ===== ===================== - - See `~.Axes.set_anchor` for further details. + .. deprecated:: 3.11 + The *anchor* parameter is not used for 3D axes and will be + removed in a future version. It is ignored. share : bool, default: False If ``True``, apply the settings to all shared Axes. + This parameter is ignored for 3D axes. 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'): diff --git a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py index e6d11f793b46..fac26d660ac8 100644 --- a/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py +++ b/lib/mpl_toolkits/mplot3d/tests/test_axes3d.py @@ -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 @@ -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'