@@ -64,6 +64,15 @@ def __init__(
6464 Other axes to share z-limits with.
6565 proj_type : {'persp', 'ortho'}
6666 The projection type, default 'persp'.
67+ auto_add_to_figure : bool, default: True
68+ Prior to Matplotlib 3.4 Axes3D would add themselves
69+ to their host Figure on init. Other Axes class do not
70+ do this.
71+
72+ This behavior is deprecated in 3.4, the default will
73+ change to False in 3.5. The keyword will be undocumented
74+ and a non-False value will be an error in 3.6.
75+
6776 **kwargs
6877 Other optional keyword arguments:
6978
@@ -97,6 +106,8 @@ def __init__(
97106 self ._shared_z_axes .join (self , sharez )
98107 self ._adjustable = 'datalim'
99108
109+ auto_add_to_figure = kwargs .pop ('auto_add_to_figure' , True )
110+
100111 super ().__init__ (
101112 fig , rect , frameon = True , box_aspect = box_aspect , * args , ** kwargs
102113 )
@@ -129,6 +140,18 @@ def __init__(
129140 # for bounding box calculations
130141 self .spines [:].set_visible (False )
131142
143+ if auto_add_to_figure :
144+ _api .warn_deprecated (
145+ "3.4" , removal = "3.6" , message = "Axes3D(fig) adding itself "
146+ "to the figure is deprecated since %(since)s. "
147+ "Pass the keyword argument auto_add_to_figure=False "
148+ "and use fig.add_axes(ax) to suppress this warning. "
149+ "The default value of auto_add_to_figure will change to "
150+ "False in mpl3.5 and True values will "
151+ "no longer work %(removal)s. This is consistent with "
152+ "other Axes classes." )
153+ fig .add_axes (self )
154+
132155 def set_axis_off (self ):
133156 self ._axis3don = False
134157 self .stale = True
0 commit comments