From 6a2af0741539316dded0189ddc1fca3bf9e3d236 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 21 Nov 2021 18:58:41 -0500 Subject: [PATCH] FIX: deprecation of render keyword to do_3d_projection Previously we both warned and required that renderer be an accepted argument. --- lib/mpl_toolkits/mplot3d/axes3d.py | 15 +++++---- lib/mpl_toolkits/tests/test_mplot3d.py | 46 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 605e0d8e8211..7c409cf2534f 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -428,12 +428,15 @@ def do_3d_projection(artist): # deprecation has expired. return artist.do_3d_projection() - _api.warn_deprecated( - "3.4", - message="The 'renderer' parameter of " - "do_3d_projection() was deprecated in Matplotlib " - "%(since)s and will be removed %(removal)s.") - return artist.do_3d_projection(renderer) + try: + return artist.do_3d_projection() + except TypeError: + _api.warn_deprecated( + "3.4", + message="The 'renderer' parameter of " + "do_3d_projection() was deprecated in Matplotlib " + "%(since)s and will be removed %(removal)s.") + return artist.do_3d_projection(renderer) collections_and_patches = ( artist for artist in self._children diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index c3d107b40494..9d05acd86231 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -1711,3 +1711,49 @@ def test_view_init_vertical_axis( tickdir_expected = tickdirs_expected[i] tickdir_actual = axis._get_tickdir() np.testing.assert_array_equal(tickdir_expected, tickdir_actual) + + +def test_do_3d_projection_renderer_deprecation_warn(): + from matplotlib.patches import FancyArrowPatch + class Arrow3D(FancyArrowPatch): + def __init__(self, xs, ys, zs, *args, **kwargs): + super().__init__((0, 0), (0, 0), *args, **kwargs) + self._verts3d = xs, ys, zs + + def do_3d_projection(self, render): + xs3d, ys3d, zs3d = self._verts3d + xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) + self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) + + return np.min(zs) + + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + arrow_prop_dict = dict(mutation_scale=20, arrowstyle='-|>', color='k') + a = Arrow3D([0, 10], [0, 0], [0, 0], **arrow_prop_dict) + ax.add_artist(a) + + with pytest.warns(MatplotlibDeprecationWarning): + fig.canvas.draw() + + +def test_do_3d_projection_renderer_deprecation_nowarn(): + from matplotlib.patches import FancyArrowPatch + class Arrow3D(FancyArrowPatch): + def __init__(self, xs, ys, zs, *args, **kwargs): + super().__init__((0, 0), (0, 0), *args, **kwargs) + self._verts3d = xs, ys, zs + + def do_3d_projection(self): + xs3d, ys3d, zs3d = self._verts3d + xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, self.axes.M) + self.set_positions((xs[0], ys[0]), (xs[1], ys[1])) + + return np.min(zs) + + fig = plt.figure() + ax = fig.add_subplot(111, projection='3d') + arrow_prop_dict = dict(mutation_scale=20, arrowstyle='-|>', color='k') + a = Arrow3D([0, 10], [0, 0], [0, 0], **arrow_prop_dict) + ax.add_artist(a) + fig.canvas.draw()