Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 07cfa22

Browse filesBrowse files
committed
FIX: allow add option for Axes3D(fig)
1 parent 9d12377 commit 07cfa22
Copy full SHA for 07cfa22

File tree

Expand file treeCollapse file tree

4 files changed

+21
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+21
-3
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+6Lines 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

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/mplot3d/axes3d.py
+10Lines 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

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55

6-
from mpl_toolkits.mplot3d import Axes3D, axes3d, proj3d, art3d
6+
from mpl_toolkits.mplot3d import axes3d, proj3d, art3d
77
import matplotlib as mpl
88
from matplotlib.backend_bases import MouseButton
99
from matplotlib import cm
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.