Skip to content

Commit b03e0b2

Browse files
authored
Merge pull request #9285 from tacaswell/fix_fullymasked_image
FIX: handle fully masked data
2 parents 1976408 + 63d3fb0 commit b03e0b2

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/matplotlib/image.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,14 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
368368
scaled_dtype = A.dtype
369369
else:
370370
scaled_dtype = np.float32
371-
# old versions of numpy do not work with `np.nammin`
372-
# and `np.nanmax` as inputs
373-
a_min = np.ma.min(A).astype(scaled_dtype)
374-
a_max = np.ma.max(A).astype(scaled_dtype)
371+
372+
a_min = A.min()
373+
if a_min is np.ma.masked:
374+
a_min, a_max = 0, 1 # all masked, so values don't matter
375+
else:
376+
a_min = a_min.astype(scaled_dtype)
377+
a_max = A.max().astype(scaled_dtype)
378+
375379
# scale the input data to [.1, .9]. The Agg
376380
# interpolators clip to [0, 1] internally, use a
377381
# smaller input scale to identify which of the

lib/matplotlib/tests/test_image.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,3 +835,13 @@ def test_imshow_deprecated_interd_warn():
835835
with warnings.catch_warnings(record=True) as warns:
836836
getattr(im, k)
837837
assert len(warns) == 1
838+
839+
840+
def test_full_invalid():
841+
x = np.ones((10, 10))
842+
x[:] = np.nan
843+
844+
f, ax = plt.subplots()
845+
ax.imshow(x)
846+
847+
f.canvas.draw()

0 commit comments

Comments
 (0)