|
2 | 2 | import re, warnings
|
3 | 3 | from cbook import iterable, flatten
|
4 | 4 | from transforms import Bbox, IdentityTransform, TransformedBbox, TransformedPath
|
| 5 | +from path import Path |
5 | 6 |
|
6 | 7 | ## Note, matplotlib artists use the doc strings for set and get
|
7 | 8 | # methods to enable the introspection methods of setp and getp. Every
|
@@ -285,25 +286,48 @@ def set_clip_box(self, clipbox):
|
285 | 286 |
|
286 | 287 | def set_clip_path(self, path, transform=None):
|
287 | 288 | """
|
288 |
| - Set the artist's clip path |
| 289 | + Set the artist's clip path, which may be: |
289 | 290 |
|
290 |
| - ACCEPTS: a Path instance and a Transform instance, or a Patch instance |
| 291 | + a) a Patch (or subclass) instance |
| 292 | +
|
| 293 | + b) a Path instance, in which cas aoptional transform may |
| 294 | + be provided, which will be applied to the path before using it |
| 295 | + for clipping. |
| 296 | +
|
| 297 | + c) None, to remove the clipping path |
| 298 | +
|
| 299 | + For efficiency, if the path happens to be an axis-aligned |
| 300 | + rectangle, this method will set the clipping box to the |
| 301 | + corresponding rectangle and set the clipping path to None. |
| 302 | + |
| 303 | + ACCEPTS: a Path instance and a Transform instance, a Patch |
| 304 | + instance, or None |
291 | 305 | """
|
292 | 306 | from patches import Patch, Rectangle
|
| 307 | + |
| 308 | + success = False |
293 | 309 | if transform is None:
|
294 | 310 | if isinstance(path, Rectangle):
|
295 | 311 | self.clipbox = TransformedBbox(Bbox.unit(), path.get_transform())
|
| 312 | + success = True |
296 | 313 | elif isinstance(path, Patch):
|
297 | 314 | self._clippath = TransformedPath(
|
298 | 315 | path.get_path(),
|
299 | 316 | path.get_transform())
|
300 |
| - elif path is None: |
301 |
| - self._clippath = None |
302 |
| - else: |
303 |
| - raise TypeError("Invalid arguments to set_clip_path") |
304 |
| - else: |
| 317 | + success = True |
| 318 | + |
| 319 | + if path is None: |
| 320 | + self._clippath = None |
| 321 | + success = True |
| 322 | + elif isinstance(path, Path): |
305 | 323 | self._clippath = TransformedPath(path, transform)
|
306 |
| - self._clipon = self.clipbox is not None or path is not None |
| 324 | + success = True |
| 325 | + |
| 326 | + if not success: |
| 327 | + print type(path), type(transform) |
| 328 | + raise TypeError("Invalid arguments to set_clip_path") |
| 329 | + |
| 330 | + self._clipon = self.clipbox is not None or self._clippath is not None |
307 | 331 | self.pchanged()
|
308 | 332 |
|
309 | 333 | def get_alpha(self):
|
@@ -334,6 +358,10 @@ def get_clip_path(self):
|
334 | 358 | return self._clippath
|
335 | 359 |
|
336 | 360 | def get_transformed_clip_path_and_affine(self):
|
| 361 | + ''' |
| 362 | + Return the clip path with the non-affine part of its transformation applied, |
| 363 | + and the remaining affine part of its transformation. |
| 364 | + ''' |
337 | 365 | if self._clippath is not None:
|
338 | 366 | return self._clippath.get_transformed_path_and_affine()
|
339 | 367 | return None, None
|
|
0 commit comments