Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83b3fef

Browse files
authored
Merge pull request #26253 from LemonBoy/inf-surf
Filter out inf values in plot_surface
2 parents 427392e + ba7af99 commit 83b3fef

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

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

1711-
# In cases where there are NaNs in the data (possibly from masked
1712-
# arrays), artifacts can be introduced. Here check whether NaNs exist
1713-
# and remove the entries if so
1714-
if not isinstance(polys, np.ndarray) or np.isnan(polys).any():
1711+
# In cases where there are non-finite values in the data (possibly NaNs from
1712+
# masked arrays), artifacts can be introduced. Here check whether such values
1713+
# are present and remove them.
1714+
if not isinstance(polys, np.ndarray) or not np.isfinite(polys).all():
17151715
new_polys = []
17161716
new_colset = []
17171717

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

lib/mpl_toolkits/mplot3d/tests/test_axes3d.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,3 +2244,16 @@ def test_scatter_masked_color():
22442244
# Assert sizes' equality
22452245
assert len(path3d.get_offsets()) ==\
22462246
len(super(type(path3d), path3d).get_facecolors())
2247+
2248+
2249+
@mpl3d_image_comparison(['surface3d_zsort_inf.png'], style='mpl20')
2250+
def test_surface3d_zsort_inf():
2251+
fig = plt.figure()
2252+
ax = fig.add_subplot(projection='3d')
2253+
2254+
x, y = np.mgrid[-2:2:0.1, -2:2:0.1]
2255+
z = np.sin(x)**2 + np.cos(y)**2
2256+
z[x.shape[0] // 2:, x.shape[1] // 2:] = np.inf
2257+
2258+
ax.plot_surface(x, y, z, cmap='jet')
2259+
ax.view_init(elev=45, azim=145)

0 commit comments

Comments
 (0)