8000 Make Poly3DCollection.set_zsort less lenient. · matplotlib/matplotlib@f543a16 · GitHub
[go: up one dir, main page]

Skip to content

Commit f543a16

Browse files
committed
Make Poly3DCollection.set_zsort less lenient.
set_zsort(False) has never worked (it ultimately raises ValueError('whoops') in `draw()` since mplot3d was first merged in edd492e), so just don't pretend to support it. Once support for False is removed, it makes sense to also deprecate support for True, which was a synonym for 'average', and just accept the three strings 'average', 'min', and 'max'. And let's not silently drop invalid strings...
1 parent 5e01393 commit f543a16

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Poly3DCollection.set_zsort
2+
``````````````````````````
3+
4+
`Poly3DCollection.set_zsort` no longer silently ignores invalid inputs, or
5+
False (which was always broken). Passing True to mean "average" is deprecated.

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ class Poly3DCollection(PolyCollection):
506506
A collection of 3D polygons.
507507
"""
508508

509-
def __init__(self, verts, *args, zsort=True, **kwargs):
509+
def __init__(self, verts, *args, zsort='average', **kwargs):
510510
"""
511511
Create a Poly3DCollection.
512512
@@ -534,26 +534,18 @@ def set_zsort(self, zsort):
534534
535535
Parameters
536536
----------
537-
zsort : bool or {'average', 'min', 'max'}
538-
For 'average', 'min', 'max' the z-order is determined by applying
539-
the function to the z-coordinates of the vertices in the viewer's
540-
coordinate system. *True* is equivalent to 'average'.
537+
zsort : {'average', 'min', 'max'}
538+
The function applied on the z-coordinates of the vertices in the
539+
viewer's coordinate system, to determine the z-order. *True* is
540+
deprecated and equivalent to 'average'.
541541
"""
542-
543542
if zsort is True:
543+
cbook.warn_deprecated(
544+
"3.1", "Passing True to mean 'average' for set_zsort is "
545+
"deprecated; pass 'average' instead.")
544546
zsort = 'average'
545-
546-
if zsort is not False:
547-
if zsort in self._zsort_functions:
548-
zsortfunc = self._zsort_functions[zsort]
549-
else:
550-
return False
551-
else:
552-
zsortfunc = None
553-
554-
self._zsort = zsort
547+
self._zsortfunc = self._zsort_functions[zsort]
555548
self._sort_zpos = None
556-
self._zsortfunc = zsortfunc
557549
self.stale = True
558550

559551
def get_vector(self, segments3d):
@@ -633,15 +625,12 @@ def do_3d_projection(self, renderer):
633625
else:
634626
cedge = cedge.repeat(len(xyzlist), axis=0)
635627

636-
# if required sort by depth (furthest drawn first)
637-
if self._zsort:
638-
z_segments_2d = sorted(
639-
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
640-
for idx, ((xs, ys, zs), fc, ec)
641-
in enumerate(zip(xyzlist, cface, cedge))),
642-
key=lambda x: x[0], reverse=True)
643-
else:
644-
raise ValueError("whoops")
628+
# sort by depth (furthest drawn first)
629+
z_segments_2d = sorted(
630+
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
631+
for idx, ((xs, ys, zs), fc, ec)
632+
in enumerate(zip(xyzlist, cface, cedge))),
633+
key=lambda x: x[0], reverse=True)
645634

646635
segments_2d = [s for z, s, fc, ec, idx in z_segments_2d]
647636
if self._codes3d is not None:

0 commit comments

Comments
 (0)
0