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

Skip to content

Fix some incorrect image clipping #17496

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 2 commits into from
May 25, 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
11 changes: 6 additions & 5 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def flush_images():
del image_group[:]

for a in artists:
if isinstance(a, _ImageBase) and a.can_composite():
if (isinstance(a, _ImageBase) and a.can_composite() and
a.get_clip_on()):
image_group.append(a)
else:
flush_images()
Expand Down Expand Up @@ -886,10 +887,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
x1, x2, y1, y2 = self.get_extent()
bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
transformed_bbox = TransformedBbox(bbox, trans)
return self._make_image(
self._A, bbox, transformed_bbox,
self.get_clip_box() or self.axes.bbox,
magnification, unsampled=unsampled)
clip = ((self.get_clip_box() or self.axes.bbox) if self.get_clip_on()
else self.figure.bbox)
return self._make_image(self._A, bbox, transformed_bbox, clip,
magnification, unsampled=unsampled)

def _check_unsampled_image(self):
"""Return whether the image would be better drawn unsampled."""
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,18 @@ def test_relim():
assert ax.get_xlim() == ax.get_ylim() == (0, 1)


def test_unclipped():
fig, ax = plt.subplots()
ax.set_axis_off()
im = ax.imshow([[0, 0], [0, 0]], aspect="auto", extent=(-10, 10, -10, 10),
cmap='gray', clip_on=False)
ax.set(xlim=(0, 1), ylim=(0, 1))
fig.canvas.draw()
# The unclipped image should fill the *entire* figure and be black.
# Ignore alpha for this comparison.
assert (np.array(fig.canvas.buffer_rgba())[..., :3] == 0).all()


def test_respects_bbox():
fig, axs = plt.subplots(2)
for ax in axs:
Expand Down