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 70db457

Browse filesBrowse files
authored
Merge pull request #15072 from anntzer/patheffects
Cleanup patheffects.
2 parents 7bf8db3 + 3b6a88a commit 70db457
Copy full SHA for 70db457

File tree

Expand file treeCollapse file tree

2 files changed

+16
-31
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-31
lines changed
Open diff view settings
Collapse file

‎lib/matplotlib/patheffects.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/patheffects.py
+14-26Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@ def __init__(self, offset=(0., 0.)):
2626
The offset to apply to the path, measured in points.
2727
"""
2828
self._offset = offset
29-
self._offset_trans = mtransforms.Affine2D()
3029

31-
def _offset_transform(self, renderer, transform):
30+
def _offset_transform(self, renderer):
3231
"""Apply the offset to the given transform."""
33-
offset_x = renderer.points_to_pixels(self._offset[0])
34-
offset_y = renderer.points_to_pixels(self._offset[1])
35-
return transform + self._offset_trans.clear().translate(offset_x,
36-
offset_y)
32+
return mtransforms.Affine2D().translate(
33+
*map(renderer.points_to_pixels, self._offset))
3734

3835
def _update_gc(self, gc, new_gc_dict):
3936
"""
@@ -180,14 +177,11 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
180177
"""
181178
Draw the path with updated gc.
182179
"""
183-
# Do not modify the input! Use copy instead.
184-
185-
gc0 = renderer.new_gc()
180+
gc0 = renderer.new_gc() # Don't modify gc, but a copy!
186181
gc0.copy_properties(gc)
187-
188182
gc0 = self._update_gc(gc0, self._gc)
189-
trans = self._offset_transform(renderer, affine)
190-
renderer.draw_path(gc0, tpath, trans, rgbFace)
183+
renderer.draw_path(
184+
gc0, tpath, affine + self._offset_transform(renderer), rgbFace)
191185
gc0.restore()
192186

193187

@@ -246,11 +240,8 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
246240
"""
247241
Overrides the standard draw_path to add the shadow offset and
248242
necessary color changes for the shadow.
249-
250243
"""
251-
# IMPORTANT: Do not modify the input - we copy everything instead.
252-
affine0 = self._offset_transform(renderer, affine)
253-
gc0 = renderer.new_gc()
244+
gc0 = renderer.new_gc() # Don't modify gc, but a copy!
254245
gc0.copy_properties(gc)
255246

256247
if self._shadow_rgbFace is None:
@@ -265,7 +256,9 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
265256
gc0.set_linewidth(0)
266257

267258
gc0 = self._update_gc(gc0, self._gc)
268-
renderer.draw_path(gc0, tpath, affine0, shadow_rgbFace)
259+
renderer.draw_path(
260+
gc0, tpath, affine + self._offset_transform(renderer),
261+
shadow_rgbFace)
269262
gc0.restore()
270263

271264

@@ -317,11 +310,8 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
317310
"""
318311
Overrides the standard draw_path to add the shadow offset and
319312
necessary color changes for the shadow.
320-
321313
"""
322-
# IMPORTANT: Do not modify the input - we copy everything instead.
323-
affine0 = self._offset_transform(renderer, affine)
324-
gc0 = renderer.new_gc()
314+
gc0 = renderer.new_gc() # Don't modify gc, but a copy!
325315
gc0.copy_properties(gc)
326316

327317
if self._shadow_color is None:
@@ -331,13 +321,12 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
331321
else:
332322
shadow_rgbFace = self._shadow_color
333323

334-
fill_color = None
335-
336324
gc0.set_foreground(shadow_rgbFace)
337325
gc0.set_alpha(self._alpha)
338326

339327
gc0 = self._update_gc(gc0, self._gc)
340-
renderer.draw_path(gc0, tpath, affine0, fill_color)
328+
renderer.draw_path(
329+
gc0, tpath, affine + self._offset_transform(renderer))
341330
gc0.restore()
342331

343332

@@ -363,9 +352,8 @@ def __init__(self, offset=(0, 0), **kwargs):
363352
self.patch = mpatches.PathPatch([], **kwargs)
364353

365354
def draw_path(self, renderer, gc, tpath, affine, rgbFace):
366-
affine = self._offset_transform(renderer, affine)
367355
self.patch._path = tpath
368-
self.patch.set_transform(affine)
356+
self.patch.set_transform(affine + self._offset_transform(renderer))
369357
self.patch.set_clip_box(gc.get_clip_rectangle())
370358
clip_path = gc.get_clip_path()
371359
if clip_path:
Collapse file

‎lib/matplotlib/tests/test_patheffects.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_patheffects.py
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,14 @@ def test_patheffects_stroked_text():
9797
ax.axis('off')
9898

9999

100-
@pytest.mark.xfail
101100
def test_PathEffect_points_to_pixels():
102101
fig = plt.figure(dpi=150)
103102
p1, = plt.plot(range(10))
104103
p1.set_path_effects([path_effects.SimpleLineShadow(),
105104
path_effects.Normal()])
106-
107105
renderer = fig.canvas.get_renderer()
108-
pe_renderer = path_effects.SimpleLineShadow().get_proxy_renderer(renderer)
109-
110-
assert isinstance(pe_renderer, path_effects.PathEffectRenderer)
106+
pe_renderer = path_effects.PathEffectRenderer(
107+
p1.get_path_effects(), renderer)
111108
# Confirm that using a path effects renderer maintains point sizes
112109
# appropriately. Otherwise rendered font would be the wrong size.
113110
assert renderer.points_to_pixels(15) == pe_renderer.points_to_pixels(15)

0 commit comments

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