Skip to content
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,14 @@ def test_text_stale():
assert not ax1.stale
assert not ax2.stale
assert not fig.stale


@image_comparison(baseline_images=['agg_text_clip'],
extensions=['png'])
def test_agg_text_clip():
np.random.seed(1)
fig, (ax1, ax2) = plt.subplots(2)
for x, y in np.random.rand(10, 2):
ax1.text(x, y, "foo", clip_on=True)
ax2.text(x, y, "foo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have gone with different text for each axes, just to be sure it's clipped to the right place.

plt.show()
8 changes: 4 additions & 4 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,14 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
typedef agg::renderer_scanline_aa<renderer_base, color_span_alloc_type, span_gen_type>
renderer_type;

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
if (angle != 0.0) {
agg::rendering_buffer srcbuf(
image.data(), (unsigned)image.dim(1),
(unsigned)image.dim(0), (unsigned)image.dim(1));
agg::pixfmt_gray8 pixf_img(srcbuf);

theRasterizer.reset_clipping();
rendererBase.reset_clipping(true);
set_clipbox(gc.cliprect, theRasterizer);

agg::trans_affine mtx;
Expand Down Expand Up @@ -786,9 +786,9 @@ inline void RendererAgg::draw_text_image(GCAgg &gc, ImageArray &image, int x, in
agg::rect_i clip;

clip.init(int(mpl_round(gc.cliprect.x1)),
int(mpl_round(gc.cliprect.y1)),
int(mpl_round(height - gc.cliprect.y2)),
int(mpl_round(gc.cliprect.x2)),
int(mpl_round(gc.cliprect.y2)));
int(mpl_round(height - gc.cliprect.y1)));
text.clip(clip);
}

Expand Down