Skip to content

Commit aefe56f

Browse files
authored
Merge pull request #24251 from oscargus/autoaddtofiguredeprecationexpiration
Expire deprecation for `auto_add_to_figure=True` in `Axes3D`
2 parents 7f0c965 + 18fbf40 commit aefe56f

File tree

5 files changed

+11
-25
lines changed

5 files changed

+11
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``auto_add_to_figure=True`` for ``Axes3D``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is no longer supported. Instead use ``fig.add_axes(ax)``.

lib/matplotlib/figure.py

-2
Original file line numberDiff line numberDiff line change
@@ -1679,8 +1679,6 @@ def _process_projection_requirements(
16791679
raise TypeError(
16801680
f"projection must be a string, None or implement a "
16811681
f"_as_mpl_axes method, not {projection!r}")
1682-
if projection_class.__name__ == 'Axes3D':
1683-
kwargs.setdefault('auto_add_to_figure', False)
16841682
return projection_class, kwargs
16851683

16861684
def get_default_bbox_extra_artists(self):

lib/matplotlib/tests/test_collections.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def test_polycollection_close():
403403
[[3., 0.], [3., 1.], [4., 1.], [4., 0.]]]
404404

405405
fig = plt.figure()
406-
ax = fig.add_axes(Axes3D(fig, auto_add_to_figure=False))
406+
ax = fig.add_axes(Axes3D(fig))
407407

408408
colors = ['r', 'g', 'b', 'y', 'k']
409409
zpos = list(range(5))

lib/mpl_toolkits/mplot3d/axes3d.py

+5-21
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ def __init__(
9999
does not produce the desired result. Note however, that a manual
100100
zorder will only be correct for a limited view angle. If the figure
101101
is rotated by the user, it will look wrong from certain angles.
102-
auto_add_to_figure : bool, default: False
103-
Prior to Matplotlib 3.4 Axes3D would add themselves
104-
to their host Figure on init. Other Axes class do not
105-
do this.
106-
107-
This behavior is deprecated in 3.4, the default is
108-
changed to False in 3.6. The keyword will be undocumented
109-
and a non-False value will be an error in 3.7.
110102
focal_length : float, default: None
111103
For a projection type of 'persp', the focal length of the virtual
112104
camera. Must be > 0. If None, defaults to 1.
@@ -145,7 +137,11 @@ def __init__(
145137
self._shared_axes["z"].join(self, sharez)
146138
self._adjustable = 'datalim'
147139

148-
auto_add_to_figure = kwargs.pop('auto_add_to_figure', False)
140+
if kwargs.pop('auto_add_to_figure', False):
141+
raise AttributeError(
142+
'auto_add_to_figure is no longer supported for Axes3D. '
143+
'Use fig.add_axes(ax) instead.'
144+
)
149145

150146
super().__init__(
151147
fig, rect, frameon=True, box_aspect=box_aspect, *args, **kwargs
@@ -177,18 +173,6 @@ def __init__(
177173
# for bounding box calculations
178174
self.spines[:].set_visible(False)
179175

180-
if auto_add_to_figure:
181-
_api.warn_deprecated(
182-
"3.4", removal="3.7", message="Axes3D(fig) adding itself "
183-
"to the figure is deprecated since %(since)s. "
184-
"Pass the keyword argument auto_add_to_figure=False "
185-
"and use fig.add_axes(ax) to suppress this warning. "
186-
"The default value of auto_add_to_figure is changed to "
187-
"False in mpl3.6 and True values will "
188-
"no longer work %(removal)s. This is consistent with "
189-
"other Axes classes.")
190-
fig.add_axes(self)
191-
192176
def set_axis_off(self):
193177
self._axis3don = False
194178
self.stale = True

lib/mpl_toolkits/tests/test_mplot3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ def test_add_collection3d_zs_scalar():
925925
@mpl3d_image_comparison(['axes3d_labelpad.png'], remove_text=False)
926926
def test_axes3d_labelpad():
927927
fig = plt.figure()
928-
ax = fig.add_axes(Axes3D(fig, auto_add_to_figure=False))
928+
ax = fig.add_axes(Axes3D(fig))
929929
# labelpad respects rcParams
930930
assert ax.xaxis.labelpad == mpl.rcParams['axes.labelpad']
931931
# labelpad can be set in set_label

0 commit comments

Comments
 (0)