Skip to content

Make Poly3DCollection.set_zsort less lenient. #12049

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

Merged
merged 1 commit into from
Sep 7, 2018
Merged
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
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/2018-09-07-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Poly3DCollection.set_zsort
``````````````````````````

`Poly3DCollection.set_zsort` no longer silently ignores invalid inputs, or
False (which was always broken). Passing True to mean "average" is deprecated.
42 changes: 16 additions & 26 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ class Poly3DCollection(PolyCollection):
A collection of 3D polygons.
"""

def __init__(self, verts, *args, zsort=True, **kwargs):
def __init__(self, verts, *args, zsort='average', **kwargs):
"""
Create a Poly3DCollection.

Expand Down Expand Up @@ -534,26 +534,19 @@ def set_zsort(self, zsort):

Parameters
----------
zsort : bool or {'average', 'min', 'max'}
For 'average', 'min', 'max' the z-order is determined by applying
the function to the z-coordinates of the vertices in the viewer's
coordinate system. *True* is equivalent to 'average'.
zsort : {'average', 'min', 'max'}
The function applied on the z-coordinates of the vertices in the
viewer's coordinate system, to determine the z-order. *True* is
deprecated and equivalent to 'average'.
"""

if zsort is True:
cbook.warn_deprecated(
"3.1", "Passing True to mean 'average' for set_zsort is "
"deprecated and support will be removed in Matplotlib 3.3; "
"pass 'average' instead.")
zsort = 'average'

if zsort is not False:
if zsort in self._zsort_functions:
zsortfunc = self._zsort_functions[zsort]
else:
return False
else:
zsortfunc = None

self._zsort = zsort
self._zsortfunc = self._zsort_functions[zsort]
self._sort_zpos = None
self._zsortfunc = zsortfunc
self.stale = True

def get_vector(self, segments3d):
Expand Down Expand Up @@ -633,15 +626,12 @@ def do_3d_projection(self, renderer):
else:
cedge = cedge.repeat(len(xyzlist), axis=0)

# if required sort by depth (furthest drawn first)
if self._zsort:
z_segments_2d = sorted(
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
for idx, ((xs, ys, zs), fc, ec)
in enumerate(zip(xyzlist, cface, cedge))),
key=lambda x: x[0], reverse=True)
else:
raise ValueError("whoops")
# sort by depth (furthest drawn first)
z_segments_2d = sorted(
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
for idx, ((xs, ys, zs), fc, ec)
in enumerate(zip(xyzlist, cface, cedge))),
key=lambda x: x[0], reverse=True)

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