Skip to content

Commit 28756a2

Browse files
QuLogicanntzer
andcommitted
Fix clipping of images with clipping disabled.
Co-authored-by: Antony Lee <anntzer.lee@gmail.com>
1 parent 56e9b41 commit 28756a2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/matplotlib/image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,10 +887,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
887887
x1, x2, y1, y2 = self.get_extent()
888888
bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
889889
transformed_bbox = TransformedBbox(bbox, trans)
890-
return self._make_image(
891-
self._A, bbox, transformed_bbox,
892-
self.get_clip_box() or self.axes.bbox,
893-
magnification, unsampled=unsampled)
890+
clip = ((self.get_clip_box() or self.axes.bbox) if self.get_clip_on()
891+
else self.figure.bbox)
892+
return self._make_image(self._A, bbox, transformed_bbox, clip,
893+
magnification, unsampled=unsampled)
894894

895895
def _check_unsampled_image(self):
896896
"""Return whether the image would be better drawn unsampled."""

lib/matplotlib/tests/test_image.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,18 @@ def test_relim():
10311031
assert ax.get_xlim() == ax.get_ylim() == (0, 1)
10321032

10331033

1034+
def test_unclipped():
1035+
fig, ax = plt.subplots()
1036+
ax.set_axis_off()
1037+
im = ax.imshow([[0, 0], [0, 0]], aspect="auto", extent=(-10, 10, -10, 10),
1038+
cmap='gray', clip_on=False)
1039+
ax.set(xlim=(0, 1), ylim=(0, 1))
1040+
fig.canvas.draw()
1041+
# The unclipped image should fill the *entire* figure and be black.
1042+
# Ignore alpha for this comparison.
1043+
assert (np.array(fig.canvas.buffer_rgba())[..., :3] == 0).all()
1044+
1045+
10341046
def test_respects_bbox():
10351047
fig, axs = plt.subplots(2)
10361048
for ax in axs:

0 commit comments

Comments
 (0)