Skip to content

Commit 245f5de

Browse files
committed
Address review comments.
1 parent c924688 commit 245f5de

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

doc/api/backend_cairo_api.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
:mod:`matplotlib.backends.backend_cairo`
33
========================================
44

5-
.. automodule:: matplotlib.backends.backend_cairo
6-
:members:
7-
:undoc-members:
8-
:show-inheritance:
5+
.. Building the docs requires either adding pycairo/cairocffi as docs build
6+
dependency, or bumping the minimal numpy version to one that supports
7+
MagicMocks (which does define `__index__`) as indices (recent numpys do, but
8+
1.7.1 doesn't).
9+
10+
.. .. automodule:: matplotlib.backends.backend_cairo
11+
.. :members:
12+
.. :undoc-members:
13+
.. :show-inheritance:

lib/matplotlib/backends/backend_cairo.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ def buffer_info(self):
7777
_CAIRO_PATH_TYPE_SIZES[cairo.PATH_CLOSE_PATH] = 1
7878

7979

80-
def _convert_path(ctx, path, transform, clip=None):
81-
return _convert_paths(ctx, [path], [transform], clip)
82-
83-
84-
def _convert_paths(ctx, paths, transforms, clip=None):
85-
return (_convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow)(
86-
ctx, paths, transforms, clip)
87-
88-
8980
def _convert_paths_slow(ctx, paths, transforms, clip=None):
9081
for path, transform in zip(paths, transforms):
9182
for points, code in path.iter_segments(transform, clip=clip):
@@ -106,7 +97,7 @@ def _convert_paths_slow(ctx, paths, transforms, clip=None):
10697

10798
def _convert_paths_fast(ctx, paths, transforms, clip=None):
10899
# We directly convert to the internal representation used by cairo, for
109-
# which ABI compatibility is guaranteed. The layout is for each item is
100+
# which ABI compatibility is guaranteed. The layout for each item is
110101
# --CODE(4)-- -LENGTH(4)- ---------PAD(8)---------
111102
# ----------X(8)---------- ----------Y(8)----------
112103
# with the size in bytes in parentheses, and (X, Y) repeated as many times
@@ -152,6 +143,13 @@ def _convert_paths_fast(ctx, paths, transforms, clip=None):
152143
cairo.cairo.cairo_append_path(ctx._pointer, ptr)
153144

154145

146+
_convert_paths = _convert_paths_fast if HAS_CAIRO_CFFI else _convert_paths_slow
147+
148+
149+
def _convert_path(ctx, path, transform, clip=None):
150+
return _convert_paths(ctx, [path], [transform], clip)
151+
152+
155153
class RendererCairo(RendererBase):
156154
fontweights = {
157155
100 : cairo.FONT_WEIGHT_NORMAL,
@@ -230,8 +228,7 @@ def draw_markers(self, gc, marker_path, marker_trans, path, transform,
230228

231229
ctx.new_path()
232230
# Create the path for the marker; it needs to be flipped here already!
233-
_convert_path(
234-
ctx, marker_path, marker_trans + Affine2D().scale(1, -1))
231+
_convert_path(ctx, marker_path, marker_trans + Affine2D().scale(1, -1))
235232
marker_path = ctx.copy_path_flat()
236233

237234
# Figure out whether the path has a fill
@@ -295,7 +292,7 @@ def _draw_paths():
295292
for k, v in gc_vars.items():
296293
try:
297294
getattr(gc, "set" + k)(v)
298-
except (AttributeError, TypeError):
295+
except (AttributeError, TypeError) as e:
299296
pass
300297
gc.ctx.new_path()
301298
paths, transforms = zip(*grouped_draw)
@@ -309,8 +306,8 @@ def _draw_paths():
309306
offsetTrans, facecolors, edgecolors, linewidths, linestyles,
310307
antialiaseds, urls, offset_position):
311308
path, transform = path_id
312-
transform = (Affine2D(transform.get_matrix()).translate(xo, yo)
313-
+ Affine2D().scale(1, -1).translate(0, self.height))
309+
transform = (Affine2D(transform.get_matrix())
310+
.translate(xo, yo - self.height).scale(1, -1))
314311
# rgb_fc could be a ndarray, for which equality is elementwise.
315312
new_key = vars(gc0), tuple(rgb_fc) if rgb_fc is not None else None
316313
if new_key == reuse_key:

0 commit comments

Comments
 (0)