From 4ddec28865b581438a31fa3a4e2c2256d628901e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 16 Sep 2020 20:31:37 -0400 Subject: [PATCH] Backport PR #18500: BUG: Fix all-masked imshow --- lib/matplotlib/image.py | 6 ++++-- lib/matplotlib/tests/test_image.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 14866cc1012c..ac5706ae7cf7 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -474,8 +474,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0, # do not run the vmin/vmax through the same pipeline we can # have values close or equal to the boundaries end up on the # wrong side. - vrange = np.array([self.norm.vmin, self.norm.vmax], - dtype=scaled_dtype) + vmin, vmax = self.norm.vmin, self.norm.vmax + if vmin is np.ma.masked: + vmin, vmax = a_min, a_max + vrange = np.array([vmin, vmax], dtype=scaled_dtype) A_scaled -= a_min vrange -= a_min diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 87e3c121d4c0..6ffb2e2d0554 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -846,6 +846,14 @@ def test_mask_image(): ax2.imshow(A, interpolation='nearest') +def test_mask_image_all(): + # Test behavior with an image that is entirely masked does not warn + data = np.full((2, 2), np.nan) + fig, ax = plt.subplots() + ax.imshow(data) + fig.canvas.draw_idle() # would emit a warning + + @image_comparison(['imshow_endianess.png'], remove_text=True) def test_imshow_endianess(): x = np.arange(10)