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

Skip to content

Fix image bbox clip. #14774

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
Aug 6, 2019
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
5 changes: 3 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,9 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
transformed_bbox = TransformedBbox(bbox, trans)
return self._make_image(
self._A, bbox, transformed_bbox, self.axes.bbox, magnification,
unsampled=unsampled)
self._A, bbox, transformed_bbox,
self.get_clip_box() or self.axes.bbox,
magnification, unsampled=unsampled)

def _check_unsampled_image(self, renderer):
"""
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_image/image_cliprect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 37 additions & 37 deletions lib/matplotlib/tests/baseline_images/test_image/image_cliprect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,21 @@ def test_deprecation():
with pytest.warns(MatplotlibDeprecationWarning):
# Enough arguments to pass "shape" positionally.
obj.imshow(data, *[None] * 10)


def test_respects_bbox():
fig, axs = plt.subplots(2)
for ax in axs:
ax.set_axis_off()
im = axs[1].imshow([[0, 1], [2, 3]], aspect="auto", extent=(0, 1, 0, 1))
im.set_clip_path(None)
# Make the image invisible in axs[1], but visible in axs[0] if we pan
# axs[1] up.
im.set_clip_box(axs[0].bbox)
buf_before = io.BytesIO()
fig.savefig(buf_before, format="rgba")
assert {*buf_before.getvalue()} == {0xff} # All white.
axs[1].set(ylim=(-1, 0))
buf_after = io.BytesIO()
fig.savefig(buf_after, format="rgba")
assert buf_before.getvalue() != buf_after.getvalue() # Not all white.