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

Skip to content

BUG: Fix all-masked imshow #18500

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 1 commit into from
Sep 17, 2020
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 @@ -470,8 +470,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 @@ -853,6 +853,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we run with warnings as error (which I'm pretty sure we don't) this test doesn't actually check that we don't issue warnings...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it failed on master before the other changes in this PR, and this suggested to me that you do:

https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/testing/conftest.py#L20

But I can wrap this in a with pytest.warns(None) as w: ... assert len(w) == 0 if it'll help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see the traceback in the description, that was from the original test on master without the fixing-changes)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest does treat warnings as errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I wasn't aware we had that turned on in conftest.py. I'm used to testing on MetPy where so many upstream dependencies have warnings at times that running with warnings is impractical. Apologies for the noise.



@image_comparison(['imshow_endianess.png'], remove_text=True)
def test_imshow_endianess():
x = np.arange(10)
Expand Down