Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4128a7

Browse files
authored
Merge pull request #18500 from larsoner/masked
BUG: Fix all-masked imshow
2 parents ffd9767 + aac5eb1 commit a4128a7

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
@@ -471,8 +471,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
471471
# do not run the vmin/vmax through the same pipeline we can
472472
# have values close or equal to the boundaries end up on the
473473
# wrong side.
474-
vrange = np.array([self.norm.vmin, self.norm.vmax],
475-
dtype=scaled_dtype)
474+
vmin, vmax = self.norm.vmin, self.norm.vmax
475+
if vmin is np.ma.masked:
476+
vmin, vmax = a_min, a_max
477+
vrange = np.array([vmin, vmax], dtype=scaled_dtype)
476478

477479
A_scaled -= a_min
478480
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)