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 6366210

Browse filesBrowse files
committed
ENH: Add TransformedPatchPath for clipping.
By linking to the Patch instead of its Path, the clip path can automatically update whenever the underlying Patch changes.
1 parent 349ff97 commit 6366210
Copy full SHA for 6366210

File tree

Expand file treeCollapse file tree

2 files changed

+45
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+45
-4
lines changed

‎lib/matplotlib/artist.py

Copy file name to clipboardExpand all lines: lib/matplotlib/artist.py
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from matplotlib.cbook import mplDeprecation
1313
from matplotlib import docstring, rcParams
1414
from .transforms import (Bbox, IdentityTransform, TransformedBbox,
15-
TransformedPath, Transform)
15+
TransformedPatchPath, TransformedPath, Transform)
1616
from .path import Path
1717

1818
# Note, matplotlib artists use the doc strings for set and get
@@ -685,9 +685,7 @@ def set_clip_path(self, path, transform=None):
685685
self._clippath = None
686686
success = True
687687
elif isinstance(path, Patch):
688-
self._clippath = TransformedPath(
689-
path.get_path(),
690-
path.get_transform())
688+
self._clippath = TransformedPatchPath(path)
691689
success = True
692690
elif isinstance(path, tuple):
693691
path, transform = path
@@ -698,6 +696,9 @@ def set_clip_path(self, path, transform=None):
698696
elif isinstance(path, Path):
699697
self._clippath = TransformedPath(path, transform)
700698
success = True
699+
elif isinstance(path, TransformedPatchPath):
700+
self._clippath = path
701+
success = True
701702
elif isinstance(path, TransformedPath):
702703
self._clippath = path
703704
success = True

‎lib/matplotlib/transforms.py

Copy file name to clipboardExpand all lines: lib/matplotlib/transforms.py
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,6 +2704,46 @@ def get_affine(self):
27042704
return self._transform.get_affine()
27052705

27062706

2707+
class TransformedPatchPath(TransformedPath):
2708+
"""
2709+
A :class:`TransformedPatchPath` caches a non-affine transformed copy of
2710+
the :class:`~matplotlib.path.Patch`. This cached copy is automatically
2711+
updated when the non-affine part of the transform or the patch changes.
2712+
"""
2713+
def __init__(self, patch):
2714+
"""
2715+
Create a new :class:`TransformedPatchPath` from the given
2716+
:class:`~matplotlib.path.Patch`.
2717+
"""
2718+
TransformNode.__init__(self)
2719+
2720+
transform = patch.get_transform()
2721+
self._patch = patch
2722+
self._transform = transform
2723+
self.set_children(transform)
2724+
self._path = patch.get_path()
2725+
self._transformed_path = None
2726+
self._transformed_points = None
2727+
2728+
def _revalidate(self):
2729+
patch_path = self._patch.get_path()
2730+
# Only recompute if the invalidation includes the non_affine part of
2731+
# the transform, or the Patch's Path has changed.
2732+
if (self._transformed_path is None or self._path != patch_path or
2733+
(self._invalid & self.INVALID_NON_AFFINE ==
2734+
self.INVALID_NON_AFFINE)):
2735+
self._path = patch_path
2736+
self._transformed_path = \
2737+
self._transform.transform_path_non_affine(patch_path)
2738+
self._transformed_points = \
2739+
Path._fast_from_codes_and_verts(
2740+
self._transform.transform_non_affine(patch_path.vertices),
2741+
None,
2742+
{'interpolation_steps': patch_path._interpolation_steps,
2743+
'should_simplify': patch_path.should_simplify})
2744+
self._invalid = 0
2745+
2746+
27072747
def nonsingular(vmin, vmax, expander=0.001, tiny=1e-15, increasing=True):
27082748
'''
27092749
Modify the endpoints of a range as needed to avoid singularities.

0 commit comments

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