Skip to content

Commit f2f407f

Browse files
committed
Ensure polygons that are not entirely nans are handled correctly
1 parent 498bcdd commit f2f407f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -733,16 +733,14 @@ def set_zsort(self, zsort):
733733
The function applied on the z-coordinates of the vertices in the
734734
viewer's coordinate system, to determine the z-order.
735735
"""
736-
def nansafe(func):
737-
def f(x):
738-
value = func(x)
739-
return np.inf if np.isnan(value) else value
740-
return f
741-
742-
self._zsortfunc = nansafe(self._zsort_functions[zsort])
736+
self._zsortfunc = self._zsort_functions[zsort]
743737
self._sort_zpos = None
744738
self.stale = True
745739

740+
def _zsortval(self, zs):
741+
nans = np.isnan(zs)
742+
return np.inf if nans.all() else self._zsortfunc(zs[~nans])
743+
746744
def get_vector(self, segments3d):
747745
"""Optimize points for projection."""
748746
if len(segments3d):
@@ -821,7 +819,7 @@ def do_3d_projection(self, renderer=None):
821819
if xyzlist:
822820
# sort by depth (furthest drawn first)
823821
z_segments_2d = sorted(
824-
((self._zsortfunc(zs), np.column_stack([xs, ys]), fc, ec, idx)
822+
((self._zsortval(zs), np.column_stack([xs, ys]), fc, ec, idx)
825823
for idx, ((xs, ys, zs), fc, ec)
826824
in enumerate(zip(xyzlist, cface, cedge))),
827825
key=lambda x: x[0], reverse=True)

0 commit comments

Comments
 (0)