Skip to content

Commit d8594bf

Browse files
authored
Merge pull request matplotlib#22058 from dstansby/mplot3d-depr
API: Remove exprired mplot3d deprecations for 3.6
2 parents 61fa334 + e629cd6 commit d8594bf

File tree

4 files changed

+72
-163
lines changed

4 files changed

+72
-163
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Removal of mplot3d deprecations
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The deprecated ``renderer`` arguments have been removed from:
4+
5+
- `.Line3DCollection.do_3d_projection`
6+
- `.Patch3D.do_3d_projection`
7+
- `.PathPatch3D.do_3d_projection`
8+
- `.Path3DCollection.do_3d_projection`
9+
- `.Patch3DCollection.do_3d_projection`
10+
- `.Poly3DCollection.do_3d_projection`
11+
12+
The deprecated ``project`` argument has also been removed from
13+
``Line3DCollection.draw()``.
14+
15+
Passing arguments not specifically listed in the signatures of
16+
`.Axes3D.plot_surface` and `.Axes3D.plot_wireframe` is no longer supported.
17+
Pass any extra arguments as keyword arguments instead.
18+
19+
These properties of the 3D Axes that were placed on the Renderer during draw
20+
have been removed:
21+
22+
* ``renderer.M``
23+
* ``renderer.eye``
24+
* ``renderer.vvec``
25+
* ``renderer.get_axis_position``
26+
27+
These attributes are all available via `.Axes3D`, which can be accessed via
28+
``self.axes`` on all `.Artist`\s.

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import numpy as np
1313

1414
from matplotlib import (
15-
_api, artist, cbook, colors as mcolors, lines, text as mtext,
16-
path as mpath)
15+
artist, cbook, colors as mcolors, lines, text as mtext, path as mpath)
1716
from matplotlib.collections import (
1817
LineCollection, PolyCollection, PatchCollection, PathCollection)
1918
from matplotlib.colors import Normalize
@@ -297,8 +296,7 @@ def set_segments(self, segments):
297296
self._segments3d = segments
298297
super().set_segments([])
299298

300-
@_api.delete_parameter('3.4', 'renderer')
301-
def do_3d_projection(self, renderer=None):
299+
def do_3d_projection(self):
302300
"""
303301
Project the points according to renderer matrix.
304302
"""
@@ -313,14 +311,6 @@ def do_3d_projection(self, renderer=None):
313311
minz = min(minz, min(zs))
314312
return minz
315313

316-
@artist.allow_rasterization
317-
@_api.delete_parameter('3.4', 'project',
318-
alternative='Line3DCollection.do_3d_projection')
319-
def draw(self, renderer, project=False):
320-
if project:
321-
self.do_3d_projection()
322-
super().draw(renderer)
323-
324314

325315
def line_collection_2d_to_3d(col, zs=0, zdir='z'):
326316
"""Convert a LineCollection to a Line3DCollection object."""
@@ -346,8 +336,7 @@ def set_3d_properties(self, verts, zs=0, zdir='z'):
346336
def get_path(self):
347337
return self._path2d
348338

349-
@_api.delete_parameter('3.4', 'renderer')
350-
def do_3d_projection(self, renderer=None):
339+
def do_3d_projection(self):
351340
s = self._segment3d
352341
xs, ys, zs = zip(*s)
353342
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
@@ -370,8 +359,7 @@ def set_3d_properties(self, path, zs=0, zdir='z'):
370359
Patch3D.set_3d_properties(self, path.vertices, zs=zs, zdir=zdir)
371360
self._code3d = path.codes
372361

373-
@_api.delete_parameter('3.4', 'renderer')
374-
def do_3d_projection(self, renderer=None):
362+
def do_3d_projection(self):
375363
s = self._segment3d
376364
xs, ys, zs = zip(*s)
377365
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
@@ -466,8 +454,7 @@ def set_3d_properties(self, zs, zdir):
466454
self._vzs = None
467455
self.stale = True
468456

469-
@_api.delete_parameter('3.4', 'renderer')
470-
def do_3d_projection(self, renderer=None):
457+
def do_3d_projection(self):
471458
xs, ys, zs = self._offsets3d
472459
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
473460
self.axes.M)
@@ -594,8 +581,7 @@ def set_depthshade(self, depthshade):
594581
self._depthshade = depthshade
595582
self.stale = True
596583

597-
@_api.delete_parameter('3.4', 'renderer')
598-
def do_3d_projection(self, renderer=None):
584+
def do_3d_projection(self):
599585
xs, ys, zs = self._offsets3d
600586
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs,
601587
self.axes.M)
@@ -786,8 +772,7 @@ def set_sort_zpos(self, val):
786772
self._sort_zpos = val
787773
self.stale = True
788774

789-
@_api.delete_parameter('3.4', 'renderer')
790-
def do_3d_projection(self, renderer=None):
775+
def do_3d_projection(self):
791776
"""
792777
Perform the 3D projection for this object.
793778
"""

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 37 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from collections import defaultdict
1414
import functools
15-
import inspect
1615
import itertools
1716
import math
1817
from numbers import Integral
@@ -405,82 +404,41 @@ def draw(self, renderer):
405404

406405
# add the projection matrix to the renderer
407406
self.M = self.get_proj()
408-
props3d = {
409-
# To raise a deprecation, we need to wrap the attribute in a
410-
# function, but binding that to an instance does not work, as you
411-
# would end up with an instance-specific method. Properties are
412-
# class-level attributes which *are* functions, so we do that
413-
# instead.
414-
# This dictionary comprehension creates deprecated properties for
415-
# the attributes listed below, and they are temporarily attached to
416-
# the _class_ in the `_setattr_cm` call. These can both be removed
417-
# once the deprecation expires
418-
name: _api.deprecated('3.4', name=name,
419-
alternative=f'self.axes.{name}')(
420-
property(lambda self, _value=getattr(self, name): _value))
421-
for name in ['M', 'vvec', 'eye', 'get_axis_position']
422-
}
423-
424-
with cbook._setattr_cm(type(renderer), **props3d):
425-
def do_3d_projection(artist):
426-
"""
427-
Call `do_3d_projection` on an *artist*, and warn if passing
428-
*renderer*.
429-
430-
Attempt to bind the empty signature first, so external Artists
431-
can avoid the deprecation warning if they support the new
432-
calling convention.
433-
"""
434-
try:
435-
signature = inspect.signature(artist.do_3d_projection)
436-
signature.bind()
437-
# ValueError if `inspect.signature` cannot provide a signature
438-
# and TypeError if the binding fails or the object does not
439-
# appear to be callable - the next call will then re-raise.
440-
except (ValueError, TypeError):
441-
_api.warn_deprecated(
442-
"3.4",
443-
message="The 'renderer' parameter of "
444-
"do_3d_projection() was deprecated in Matplotlib "
445-
"%(since)s and will be removed %(removal)s.")
446-
return artist.do_3d_projection(renderer)
447-
else:
448-
# Call this directly once the deprecation period expires.
449-
return artist.do_3d_projection()
450-
451-
collections_and_patches = (
452-
artist for artist in self._children
453-
if isinstance(artist, (mcoll.Collection, mpatches.Patch))
454-
and artist.get_visible())
455-
if self.computed_zorder:
456-
# Calculate projection of collections and patches and zorder
457-
# them. Make sure they are drawn above the grids.
458-
zorder_offset = max(axis.get_zorder()
459-
for axis in self._get_axis_list()) + 1
460-
collection_zorder = patch_zorder = zorder_offset
461-
for artist in sorted(collections_and_patches,
462-
key=do_3d_projection,
463-
reverse=True):
464-
if isinstance(artist, mcoll.Collection):
465-
artist.zorder = collection_zorder
466-
collection_zorder += 1
467-
elif isinstance(artist, mpatches.Patch):
468-
artist.zorder = patch_zorder
469-
patch_zorder += 1
470-
else:
471-
for artist in collections_and_patches:
472-
artist.do_3d_projection()
473407

474-
if self._axis3don:
475-
# Draw panes first
476-
for axis in self._get_axis_list():
477-
axis.draw_pane(renderer)
478-
# Then axes
479-
for axis in self._get_axis_list():
480-
axis.draw(renderer)
408+
collections_and_patches = (
409+
artist for artist in self._children
410+
if isinstance(artist, (mcoll.Collection, mpatches.Patch))
411+
and artist.get_visible())
412+
if self.computed_zorder:
413+
# Calculate projection of collections and patches and zorder
414+
# them. Make sure they are drawn above the grids.
415+
zorder_offset = max(axis.get_zorder()
416+
for axis in self._get_axis_list()) + 1
417+
collection_zorder = patch_zorder = zorder_offset
418+
419+
for artist in sorted(collections_and_patches,
420+
key=lambda artist: artist.do_3d_projection(),
421+
reverse=True):
422+
if isinstance(artist, mcoll.Collection):
423+
artist.zorder = collection_zorder
424+
collection_zorder += 1
425+
elif isinstance(artist, mpatches.Patch):
426+
artist.zorder = patch_zorder
427+
patch_zorder += 1
428+
else:
429+
for artist in collections_and_patches:
430+
artist.do_3d_projection()
431+
432+
if self._axis3don:
433+
# Draw panes first
434+
for axis in self._get_axis_list():
435+
axis.draw_pane(renderer)
436+
# Then axes
437+
for axis in self._get_axis_list():
438+
axis.draw(renderer)
481439

482-
# Then rest
483-
super().draw(renderer)
440+
# Then rest
441+
super().draw(renderer)
484442

485443
def get_axis_position(self):
486444
vals = self.get_w_lims()
@@ -1504,8 +1462,7 @@ def plot(self, xs, ys, *args, zdir='z', **kwargs):
15041462

15051463
plot3D = plot
15061464

1507-
@_api.delete_parameter("3.4", "args", alternative="kwargs")
1508-
def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
1465+
def plot_surface(self, X, Y, Z, *, norm=None, vmin=None,
15091466
vmax=None, lightsource=None, **kwargs):
15101467
"""
15111468
Create a surface plot.
@@ -1679,7 +1636,7 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
16791636

16801637
# note that the striding causes some polygons to have more coordinates
16811638
# than others
1682-
polyc = art3d.Poly3DCollection(polys, *args, **kwargs)
1639+
polyc = art3d.Poly3DCollection(polys, **kwargs)
16831640

16841641
if fcolors is not None:
16851642
if shade:
@@ -1790,8 +1747,7 @@ def norm(x):
17901747

17911748
return colors
17921749

1793-
@_api.delete_parameter("3.4", "args", alternative="kwargs")
1794-
def plot_wireframe(self, X, Y, Z, *args, **kwargs):
1750+
def plot_wireframe(self, X, Y, Z, **kwargs):
17951751
"""
17961752
Plot a 3D wireframe.
17971753
@@ -1903,7 +1859,7 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
19031859
+ [list(zip(xl, yl, zl))
19041860
for xl, yl, zl in zip(txlines, tylines, tzlines)])
19051861

1906-
linec = art3d.Line3DCollection(lines, *args, **kwargs)
1862+
linec = art3d.Line3DCollection(lines, **kwargs)
19071863
self.add_collection(linec)
19081864
self.auto_scale_xyz(X, Y, Z, had_data)
19091865

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,63 +1713,3 @@ def test_view_init_vertical_axis(
17131713
tickdir_expected = tickdirs_expected[i]
17141714
tickdir_actual = axis._get_tickdir()
17151715
np.testing.assert_array_equal(tickdir_expected, tickdir_actual)
1716-
1717-
1718-
def test_do_3d_projection_renderer_deprecation_warn_on_argument():
1719-
"""
1720-
Test that an external artist with an old-style calling convention raises
1721-
a suitable deprecation warning.
1722-
"""
1723-
class DummyPatch(art3d.Patch3D):
1724-
def do_3d_projection(self, renderer):
1725-
return 0
1726-
1727-
def draw(self, renderer):
1728-
pass
1729-
1730-
fig = plt.figure()
1731-
ax = fig.add_subplot(111, projection='3d')
1732-
artist = DummyPatch()
1733-
ax.add_artist(artist)
1734-
1735-
match = r"The 'renderer' parameter of do_3d_projection\(\) was deprecated"
1736-
with pytest.warns(MatplotlibDeprecationWarning, match=match):
1737-
fig.canvas.draw()
1738-
1739-
1740-
def test_do_3d_projection_renderer_deprecation_nowarn_on_optional_argument():
1741-
"""
1742-
Test that an external artist with a calling convention compatible with
1743-
both v3.3 and v3.4 does not raise a deprecation warning.
1744-
"""
1745-
class DummyPatch(art3d.Patch3D):
1746-
def do_3d_projection(self, renderer=None):
1747-
return 0
1748-
1749-
def draw(self, renderer):
1750-
pass
1751-
1752-
fig = plt.figure()
1753-
ax = fig.add_subplot(111, projection='3d')
1754-
artist = DummyPatch()
1755-
ax.add_artist(artist)
1756-
fig.canvas.draw()
1757-
1758-
1759-
def test_do_3d_projection_renderer_deprecation_nowarn_on_no_argument():
1760-
"""
1761-
Test that an external artist with a calling convention compatible with
1762-
only v3.4 does not raise a deprecation warning.
1763-
"""
1764-
class DummyPatch(art3d.Patch3D):
1765-
def do_3d_projection(self):
1766-
return 0
1767-
1768-
def draw(self, renderer):
1769-
pass
1770-
1771-
fig = plt.figure()
1772-
ax = fig.add_subplot(111, projection='3d')
1773-
artist = DummyPatch()
1774-
ax.add_artist(artist)
1775-
fig.canvas.draw()

0 commit comments

Comments
 (0)