|
1 | 1 | from __future__ import division |
2 | 2 | import sys, re |
3 | 3 | from cbook import iterable, flatten |
4 | | -from transforms import Affine2D |
| 4 | +from transforms import Affine2D, Bbox, IdentityTransform, TransformedBbox, \ |
| 5 | + TransformedPath |
5 | 6 | import matplotlib.units as units |
6 | 7 |
|
7 | 8 | ## Note, matplotlib artists use the doc strings for set and get |
@@ -145,7 +146,7 @@ def set_transform(self, t): |
145 | 146 | def get_transform(self): |
146 | 147 | 'return the Transformation instance used by this artist' |
147 | 148 | if self._transform is None: |
148 | | - self._transform = Affine2D() |
| 149 | + self._transform = IdentityTransform() |
149 | 150 | return self._transform |
150 | 151 |
|
151 | 152 | def hitlist(self,event): |
@@ -284,17 +285,29 @@ def set_clip_box(self, clipbox): |
284 | 285 | self._clipon = clipbox is not None or self._clippath is not None |
285 | 286 | self.pchanged() |
286 | 287 |
|
287 | | - def set_clip_path(self, path): |
| 288 | + def set_clip_path(self, path, transform=None): |
288 | 289 | """ |
289 | 290 | Set the artist's clip path |
290 | 291 |
|
291 | | - ACCEPTS: an agg.path_storage instance |
292 | | - """ |
293 | | - self._clippath = path |
| 292 | + ACCEPTS: a Path instance and a Transform instance, or a Patch instance |
| 293 | + """ |
| 294 | + from patches import Patch, Rectangle |
| 295 | + if transform is None: |
| 296 | + if isinstance(path, Rectangle): |
| 297 | + self.clipbox = TransformedBbox(Bbox.unit(), path.get_transform()) |
| 298 | + elif isinstance(path, Patch): |
| 299 | + self._clippath = TransformedPath( |
| 300 | + path.get_path(), |
| 301 | + path.get_transform()) |
| 302 | + elif path is None: |
| 303 | + self._clippath = None |
| 304 | + else: |
| 305 | + raise TypeError("Invalid arguments to set_clip_path") |
| 306 | + else: |
| 307 | + self._clippath = TransformedPath(path, transform) |
294 | 308 | self._clipon = self.clipbox is not None or path is not None |
295 | 309 | self.pchanged() |
296 | 310 |
|
297 | | - |
298 | 311 | def get_alpha(self): |
299 | 312 | """ |
300 | 313 | Return the alpha value used for blending - not supported on all |
@@ -431,6 +444,7 @@ def update_from(self, other): |
431 | 444 | self._alpha = other._alpha |
432 | 445 | self.clipbox = other.clipbox |
433 | 446 | self._clipon = other._clipon |
| 447 | + self._clippath = other._clippath |
434 | 448 | self._lod = other._lod |
435 | 449 | self._label = other._label |
436 | 450 | self.pchanged() |
|
0 commit comments