8000 Merge pull request #17496 from QuLogic/image-clip · matplotlib/matplotlib@626d54f · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 626d54f

Browse files
authored
Merge pull request #17496 from QuLogic/image-clip
Fix some incorrect image clipping
2 parents 36bc7da + 28756a2 commit 626d54f

File tree

4 files changed

+37
-29
lines changed

4 files changed

+37
-29
lines changed

lib/matplotlib/image.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def flush_images():
149149
del image_group[:]
150150

151151
for a in artists:
152-
if isinstance(a, _ImageBase) and a.can_composite():
152+
if (isinstance(a, _ImageBase) and a.can_composite() and
153+
a.get_clip_on()):
153154
image_group.append(a)
154155
else:
155156
flush_images()
@@ -886,10 +887,10 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
886887
x1, x2, y1, y2 = self.get_extent()
887888
bbox = Bbox(np.array([[x1, y1], [x2, y2]]))
888889
transformed_bbox = TransformedBbox(bbox, trans)
889-
return self._make_image(
890-
self._A, bbox, transformed_bbox,
891-
self.get_clip_box() or self.axes.bbox,
892-
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)
893894

894895
def _check_unsampled_image(self):
895896
"""Return whether the image would be better drawn unsampled."""
Binary file not shown.

lib/matplotlib/tests/baseline_images/test_image/bbox_image_inverted.svg

Lines changed: 19 additions & 24 deletions
Loading

lib/matplotlib/tests/test_image.py

Lines changed: 12 additions & 0 deletions
+
ax.set_axis_off()
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
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)
0