Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c52e357

Browse files
committed
cairo backend: Flush out mark drawing every 1000 marks.
This is done to prevent the path that is passed to cairo to become way too large, as very long paths may impact performance.
1 parent 0cc8287 commit c52e357

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform, rgbFace=N
173173
Affine2D().scale(1.0, -1.0).translate(0, self.height)
174174

175175
ctx.new_path()
176-
for vertices, codes in path.iter_segments(transform, simplify=False):
176+
for i, (vertices, codes) in enumerate(path.iter_segments(transform, simplify=False)):
177177
if len(vertices):
178178
x, y = vertices[-2:]
179179
ctx.save()
@@ -182,13 +182,15 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform, rgbFace=N
182182
ctx.translate(x, y)
183183
ctx.append_path(marker_path)
184184

185+
ctx.restore()
186+
185187
# Slower code path if there is a fill; we need to draw
186188
# the fill and stroke for each marker at the same time.
187-
if filled:
189+
# Also flush out the drawing every once in a while to
190+
# prevent the paths from getting way too long.
191+
if filled or i % 1000 == 0:
188192
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
189193

190-
ctx.restore()
191-
192194
# Fast path, if there is no fill, draw everything in one step
193195
if not filled:
194196
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())

0 commit comments

Comments
 (0)