Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b03e0b2

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

File tree

Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-4
lines changed

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+8-4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.