Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83b8e42

Browse files
MNT/DOC: Deprecate anchor in Axes3D.set_aspect
1 parent 63e0329 commit 83b8e42

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Parameters ``Axes3D.set_aspect(..., anchor=..., share=...)``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The parameters *anchor* and *share* of `.Axes3D.set_aspect` are deprecated.
4+
They had no effect on 3D axes and will be removed in a future version.

lib/mpl_toolkits/mplot3d/axes3d.py

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

247+
@_api.delete_parameter("3.11", "share")
248+
@_api.delete_parameter("3.11", "anchor")
247249
def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
248250
"""
249251
Set the aspect ratios.
@@ -263,39 +265,31 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
263265
'equalyz' adapt the y and z axes to have equal aspect ratios.
264266
========= ==================================================
265267
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.
268+
adjustable : {'box', 'datalim'}, default: 'box'
269+
Defines which parameter to adjust to meet the aspect ratio.
270+
271+
- 'box': Change the physical dimensions of the axes bounding box.
272+
- 'datalim': Change the x, y, or z data limits.
270273
271274
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.
275+
.. deprecated:: 3.11
276+
This parameter has no effect.
287277
288278
share : bool, default: False
289-
If ``True``, apply the settings to all shared Axes.
279+
.. deprecated:: 3.11
280+
This parameter has no effect.
290281
291282
See Also
292283
--------
293284
mpl_toolkits.mplot3d.axes3d.Axes3D.set_box_aspect
294285
"""
286+
if adjustable is None:
287+
adjustable = 'box'
288+
_api.check_in_list(['box', 'datalim'], adjustable=adjustable)
295289
_api.check_in_list(('auto', 'equal', 'equalxy', 'equalyz', 'equalxz'),
296290
aspect=aspect)
297-
super().set_aspect(
298-
aspect='auto', adjustable=adjustable, anchor=anchor, share=share)
291+
292+
self.set_adjustable(adjustable)
299293
self._aspect = aspect
300294

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

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

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

2122
import matplotlib.pyplot as plt
2223
import numpy as np
@@ -2711,3 +2712,31 @@ def test_line3dcollection_autolim_ragged():
27112712
assert np.allclose(ax.get_xlim3d(), (-0.08333333333333333, 4.083333333333333))
27122713
assert np.allclose(ax.get_ylim3d(), (-0.0625, 3.0625))
27132714
assert np.allclose(ax.get_zlim3d(), (-0.08333333333333333, 4.083333333333333))
2715+
2716+
2717+
def test_axes3d_set_aspect_deperecated_params():
2718+
"""
2719+
Test that using the deprecated 'anchor' and 'share' kwargs in
2720+
set_aspect raises the correct warning.
2721+
"""
2722+
fig = plt.figure()
2723+
ax = fig.add_subplot(projection='3d')
2724+
2725+
# Test that providing the `anchor` parameter raises a deprecation warning.
2726+
with pytest.warns(_api.MatplotlibDeprecationWarning, match="'anchor' parameter"):
2727+
ax.set_aspect('equal', anchor='C')
2728+
2729+
# Test that using the 'share' parameter is now deprecated.
2730+
with pytest.warns(_api.MatplotlibDeprecationWarning, match="'share' parameter"):
2731+
ax.set_aspect('equal', share=True)
2732+
2733+
# Test that the `adjustable` parameter is correctly processed to satisfy
2734+
# code coverage.
2735+
ax.set_aspect('equal', adjustable='box')
2736+
assert ax.get_adjustable() == 'box'
2737+
2738+
ax.set_aspect('equal', adjustable='datalim')
2739+
assert ax.get_adjustable() == 'datalim'
2740+
2741+
with pytest.raises(ValueError, match="adjustable"):
2742+
ax.set_aspect('equal', adjustable='invalid_value')

0 commit comments

Comments
 (0)