Skip to content

Navigation Menu

Sign in
Appearance settings

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 2ceaa9c

Browse filesBrowse files
authored
Merge pull request #2370 from benzea/cairo-draw-markers
Implement draw_markers in the cairo backend.
2 parents 6b1adfd + c52e357 commit 2ceaa9c
Copy full SHA for 2ceaa9c

File tree

Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+43
-0
lines changed

‎lib/matplotlib/backends/backend_cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_cairo.py
+43Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,49 @@ def draw_path(self, gc, path, transform, rgbFace=None):
167167

168168
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
169169

170+
def draw_markers(self, gc, marker_path, marker_trans, path, transform, rgbFace=None):
171+
ctx = gc.ctx
172+
173+
ctx.new_path()
174+
# Create the path for the marker; it needs to be flipped here already!
175+
self.convert_path(ctx, marker_path, marker_trans + Affine2D().scale(1.0, -1.0))
176+
marker_path = ctx.copy_path_flat()
177+
178+
# Figure out whether the path has a fill
179+
x1, y1, x2, y2 = ctx.fill_extents()
180+
if x1 == 0 and y1 == 0 and x2 == 0 and y2 == 0:
181+
filled = False
182+
# No fill, just unset this (so we don't try to fill it later on)
183+
rgbFace = None
184+
else:
185+
filled = True
186+
187+
transform = transform + \
188+
Affine2D().scale(1.0, -1.0).translate(0, self.height)
189+
190+
ctx.new_path()
191+
for i, (vertices, codes) in enumerate(path.iter_segments(transform, simplify=False)):
192+
if len(vertices):
193+
x, y = vertices[-2:]
194+
ctx.save()
195+
196+
# Translate and apply path
197+
ctx.translate(x, y)
198+
ctx.append_path(marker_path)
199+
200+
ctx.restore()
201+
202+
# Slower code path if there is a fill; we need to draw
203+
# the fill and stroke for each marker at the same time.
204+
# Also flush out the drawing every once in a while to
205+
# prevent the paths from getting way too long.
206+
if filled or i % 1000 == 0:
207+
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
208+
209+
# Fast path, if there is no fill, draw everything in one step
210+
if not filled:
211+
self._fill_and_stroke(ctx, rgbFace, gc.get_alpha(), gc.get_forced_alpha())
212+
170213
def draw_image(self, gc, x, y, im):
171214
# bbox - not currently used
172215
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.