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

Skip to content

FIX: deprecation of render keyword to do_3d_projection #21704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def do_3d_projection(self, render):
def do_3d_projection(self, renderer):

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should add a match for the specific warning text you want here.

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()