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

Skip to content

Commit bb5d1cc

Browse files
committed
FIX: allow add option for Axes3D(fig)
1 parent 9d12377 commit bb5d1cc

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,8 @@ def __init__(self, fig, rect,
645645
if yscale:
646646
self.set_yscale(yscale)
647647

648+
# remove when Axis3d deprecation expires and this kwarg is removed:
649+
kwargs.pop('add', None)
648650
self.update(kwargs)
649651

650652
for name, axis in self._get_axis_map().items():

lib/matplotlib/figure.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ def add_axes(self, *args, **kwargs):
579579
projection_class, kwargs = self._process_projection_requirements(
580580
*args, **kwargs)
581581

582+
# remove this when deprecation for Axes3d(add=True) ends:
583+
kwargs['add'] = False
582584
# create the new axes using the axes class given
583585
a = projection_class(self, rect, **kwargs)
584586
return self._add_axes_internal(a)
@@ -708,6 +710,10 @@ def add_subplot(self, *args, **kwargs):
708710
args = tuple(map(int, str(args[0])))
709711
projection_class, kwargs = self._process_projection_requirements(
710712
*args, **kwargs)
713+
714+
# remove this when deprecation for Axes3d(add=True) ends:
715+
kwargs['add'] = False
716+
711717
ax = subplot_class_factory(projection_class)(self, *args, **kwargs)
712718
return self._add_axes_internal(ax)
713719

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def __init__(
9797
self._shared_z_axes.join(self, sharez)
9898
self._adjustable = 'datalim'
9999

100+
add = kwargs.pop("add", True)
101+
100102
super().__init__(
101103
fig, rect, frameon=True, box_aspect=box_aspect, *args, **kwargs
102104
)
@@ -125,6 +127,14 @@ def __init__(
125127
pseudo_bbox = self.transLimits.inverted().transform([(0, 0), (1, 1)])
126128
self._pseudo_w, self._pseudo_h = pseudo_bbox[1] - pseudo_bbox[0]
127129

130+
if add:
131+
_api.warn_deprecated(
132+
"3.4", message="Axes3D(fig) adding itself "
133+
"to the figure is deprecated since %(since)s and will "
134+
"no longer work %(removal)s; this is consistent with "
135+
"other axes classes. Use fig.add_subplot(projection='3d')")
136+
self.figure.add_axes(self)
137+
128138
# mplot3d currently manages its own spines and needs these turned off
129139
# for bounding box calculations
130140
self.spines[:].set_visible(False)

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ def test_add_collection3d_zs_scalar():
702702
@mpl3d_image_comparison(['axes3d_labelpad.png'], remove_text=False)
703703
def test_axes3d_labelpad():
704704
fig = plt.figure()
705-
ax = fig.add_axes(Axes3D(fig))
705+
ax = fig.add_subplot(projection='3d')
706706
# labelpad respects rcParams
707707
assert ax.xaxis.labelpad == mpl.rcParams['axes.labelpad']
708708
# labelpad can be set in set_label
@@ -1109,7 +1109,7 @@ def test_inverted_cla():
11091109

11101110
def test_ax3d_tickcolour():
11111111
fig = plt.figure()
1112-
ax = Axes3D(fig)
1112+
ax = fig.add_subplot(projection="3d")
11131113

11141114
ax.tick_params(axis='x', colors='red')
11151115
ax.tick_params(axis='y', colors='red')

0 commit comments

Comments
 (0)