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

Skip to content

Backport PR #18500 on branch v3.3.x (BUG: Fix all-masked imshow) #18504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down