Skip to content

Commit 66ba515

Browse files
authored
Merge pull request #25334 from xtanion/contour_nan
Fix for all NANs in contour
2 parents d787258 + a00680e commit 66ba515

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/matplotlib/contour.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1447,12 +1447,12 @@ def _contour_args(self, args, kwargs):
14471447
else:
14481448
raise _api.nargs_error(fn, takes="from 1 to 4", given=nargs)
14491449
z = ma.masked_invalid(z, copy=False)
1450-
self.zmax = float(z.max())
1451-
self.zmin = float(z.min())
1450+
self.zmax = z.max().astype(float)
1451+
self.zmin = z.min().astype(float)
14521452
if self.logscale and self.zmin <= 0:
14531453
z = ma.masked_where(z <= 0, z)
14541454
_api.warn_external('Log scale: values of z <= 0 have been masked')
1455-
self.zmin = float(z.min())
1455+
self.zmin = z.min().astype(float)
14561456
self._process_contour_level_args(args, z.dtype)
14571457
return (x, y, z)
14581458

lib/matplotlib/tests/test_contour.py

+7
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,10 @@ def test_bool_autolevel():
715715
assert plt.tricontour(x, y, z).levels.tolist() == [.5]
716716
assert plt.tricontourf(x, y, z.tolist()).levels.tolist() == [0, .5, 1]
717717
assert plt.tricontourf(x, y, z).levels.tolist() == [0, .5, 1]
718+
719+
720+
def test_all_nan():
721+
x = np.array([[np.nan, np.nan], [np.nan, np.nan]])
722+
assert_array_almost_equal(plt.contour(x).levels,
723+
[-1e-13, -7.5e-14, -5e-14, -2.4e-14, 0.0,
724+
2.4e-14, 5e-14, 7.5e-14, 1e-13])

0 commit comments

Comments
 (0)