Skip to content

Commit a5d6753

Browse files
backend_cairo: Clip drawn paths to context.clip_extents()
+ Fixes #4054
1 parent be305a3 commit a5d6753

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/matplotlib/backends/backend_cairo.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def _fill_and_stroke (self, ctx, fill_c, alpha, alpha_overrides):
133133
ctx.stroke()
134134

135135
@staticmethod
136-
def convert_path(ctx, path, transform):
137-
for points, code in path.iter_segments(transform):
136+
def convert_path(ctx, path, transform, clip=None):
137+
for points, code in path.iter_segments(transform, clip=clip):
138138
if code == Path.MOVETO:
139139
ctx.move_to(*points)
140140
elif code == Path.CLOSEPOLY:
@@ -152,11 +152,18 @@ def convert_path(ctx, path, transform):
152152
def draw_path(self, gc, path, transform, rgbFace=None):
153153
ctx = gc.ctx
154154

155+
# We'll clip the path to the actual rendering extents
156+
# if the path isn't filled.
157+
if rgbFace is None and gc.get_hatch() is None:
158+
clip = ctx.clip_extents()
159+
else:
160+
clip = None
161+
155162
transform = transform + \
156163
Affine2D().scale(1.0, -1.0).translate(0, self.height)
157164

158165
ctx.new_path()
159-
self.convert_path(ctx, path, transform)
166+
self.convert_path(ctx, path, transform, clip)
160167

161168
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
162169

0 commit comments

Comments
 (0)