Skip to content

Commit 879793e

Browse files
committed
Filter out inf values in plot_surface
Extend the logic introduced by matplotlib#20725 for NaN values to inf values, avoiding the introduction of infinite vertices in the mesh that wreak havoc when performing the z-sorting. Sadly I don't have a minimal test case for this problem.
1 parent f7a8cab commit 879793e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,18 +1702,18 @@ def plot_surface(self, X, Y, Z, *, norm=None, vmin=None,
17021702
if fcolors is not None:
17031703
colset.append(fcolors[rs][cs])
17041704

1705-
# In cases where there are NaNs in the data (possibly from masked
1706-
# arrays), artifacts can be introduced. Here check whether NaNs exist
1707-
# and remove the entries if so
1708-
if not isinstance(polys, np.ndarray) or np.isnan(polys).any():
1705+
# In cases where there are non-finite values in the data (possibly NaNs from
1706+
# masked arrays), artifacts can be introduced. Here check whether such values are
1707+
# present and remove them.
1708+
if not isinstance(polys, np.ndarray) or not np.isfinite(polys).all():
17091709
new_polys = []
17101710
new_colset = []
17111711

17121712
# Depending on fcolors, colset is either an empty list or has as
17131713
# many elements as polys. In the former case new_colset results in
17141714
# a list with None entries, that is discarded later.
17151715
for p, col in itertools.zip_longest(polys, colset):
1716-
new_poly = np.array(p)[~np.isnan(p).any(axis=1)]
1716+
new_poly = p[np.isfinite(p).all(axis=1)].copy()
17171717
if len(new_poly):
17181718
new_polys.append(new_poly)
17191719
new_colset.append(col)

0 commit comments

Comments
 (0)