Skip to content

Commit aac5eb1

Browse files
committed
BUG: Fix all-masked data
1 parent 5584ba7 commit aac5eb1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
470470
# do not run the vmin/vmax through the same pipeline we can
471471
# have values close or equal to the boundaries end up on the
472472
# wrong side.
473-
vrange = np.array([self.norm.vmin, self.norm.vmax],
474-
dtype=scaled_dtype)
473+
vmin, vmax = self.norm.vmin, self.norm.vmax
474+
if vmin is np.ma.masked:
475+
vmin, vmax = a_min, a_max
476+
vrange = np.array([vmin, vmax], dtype=scaled_dtype)
475477

476478
A_scaled -= a_min
477479
vrange -= a_min

lib/matplotlib/tests/test_image.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,14 @@ def test_mask_image():
853853
ax2.imshow(A, interpolation='nearest')
854854

855855

856+
def test_mask_image_all():
857+
# Test behavior with an image that is entirely masked does not warn
858+
data = np.full((2, 2), np.nan)
859+
fig, ax = plt.subplots()
860+
ax.imshow(data)
861+
fig.canvas.draw_idle() # would emit a warning
862+
863+
856864
@image_comparison(['imshow_endianess.png'], remove_text=True)
857865
def test_imshow_endianess():
858866
x = np.arange(10)

0 commit comments

Comments
 (0)