Skip to content

Commit 50e9cbb

Browse files
committed
Remove NaNs from polygons in plot_surface
1 parent dba02be commit 50e9cbb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,24 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None,
16551655
if fcolors is not None:
16561656
colset.append(fcolors[rs][cs])
16571657

1658+
# In cases where there are NaNs in the data (possibly from masked
1659+
# arrays), artifacts can be introduced. Here check whether NaNs exist
1660+
# and remove the entries if so
1661+
if not isinstance(polys, np.ndarray) or np.isnan(polys).any():
1662+
new_polys = []
1663+
new_colset = []
1664+
1665+
for p, col in itertools.zip_longest(polys, colset):
1666+
new_poly = np.array(p)[~np.isnan(p).any(axis=1)]
1667+
if len(new_poly):
1668+
new_polys.append(new_poly)
1669+
new_colset.append(col)
1670+
1671+
# Replace previous polys and, if fcolors is not None, colset
1672+
polys = new_polys
1673+
if fcolors is not None:
1674+
colset = new_colset
1675+
16581676
# note that the striding causes some polygons to have more coordinates
16591677
# than others
16601678
polyc = art3d.Poly3DCollection(polys, *args, **kwargs)

0 commit comments

Comments
 (0)