8000 Merge pull request #14397 from anntzer/pcolorfast-clip_path · matplotlib/matplotlib@0edc9af · GitHub
[go: up one dir, main page]

Skip to content

Commit 0edc9af

Browse files
authored
Merge pull request #14397 from anntzer/pcolorfast-clip_path
Correctly set clip_path on pcolorfast return artist.
2 parents 4eb0037 + 7941527 commit 0edc9af

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6309,6 +6309,9 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
63096309
ret.set_clim(vmin, vmax)
63106310
elif np.ndim(C) == 2: # C.ndim == 3 is RGB(A) so doesn't need scaling.
63116311
ret.autoscale_None()
6312+
if ret.get_clip_path() is None:
6313+
# image does not already have clipping set, clip to axes patch
6314+
ret.set_clip_path(self.patch)
63126315

63136316
ret.sticky_edges.x[:] = [xl, xr]
63146317
ret.sticky_edges.y[:] = [yb, yt]

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,21 @@ def test_bbox_inches_tight_raster():
9090

9191

9292
def test_only_on_non_finite_bbox():
93-
9493
fig, ax = plt.subplots()
9594
ax.annotate("", xy=(0, float('nan')))
9695
ax.set_axis_off()
9796
# we only need to test that it does not error out on save
9897
fig.savefig(BytesIO(), bbox_inches='tight', format='png')
98+
99+
100+
def test_tight_pcolorfast():
101+
fig, ax = plt.subplots()
102+
ax.pcolorfast(np.arange(4).reshape((2, 2)))
103+
ax.set(ylim=(0, .1))
104+
buf = BytesIO()
105+
fig.savefig(buf, bbox_inches="tight")
106+
buf.seek(0)
107+
height, width, _ = plt.imread(buf).shape
108+
# Previously, the bbox would include the area of the image clipped out by
109+
# the axes, resulting in a very tall image given the y limits of (0, 0.1).
110+
assert width > height

0 commit comments

Comments
 (0)
0