Skip to content

Commit e2dd1ba

Browse files
authored
Merge pull request #18504 from meeseeksmachine/auto-backport-of-pr-18500-on-v3.3.x
Backport PR #18500 on branch v3.3.x (BUG: Fix all-masked imshow)
2 parents 6ba186c + 4ddec28 commit e2dd1ba

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

480482
A_scaled -= a_min
481483
vrange -= a_min

lib/matplotlib/tests/test_image.py

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

848848

849+
def test_mask_image_all():
850+
# Test behavior with an image that is entirely masked does not warn
851+
data = np.full((2, 2), np.nan)
852+
fig, ax = plt.subplots()
853+
ax.imshow(data)
854+
fig.canvas.draw_idle() # would emit a warning
855+
856+
849857
@image_comparison(['imshow_endianess.png'], remove_text=True)
850858
def test_imshow_endianess():
851859
x = np.arange(10)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy