9
9
import numpy as np
10
10
from numpy import ma
11
11
12
- from matplotlib ._path import point_in_path , get_path_extents , \
13
- point_in_path_collection , get_path_collection_extents , \
14
- path_in_path , path_intersects_path , convert_path_to_polygons , \
15
- cleanup_path , points_in_path , clip_path_to_rect
12
+ from matplotlib import _path
13
+
14
+ # ._path import point_in_path, get_path_extents, \
15
+ # point_in_path_collection, get_path_collection_extents, \
16
+ # path_in_path, path_intersects_path, convert_path_to_polygons, \
17
+ # cleanup_path, points_in_path, clip_path_to_rect
16
18
from matplotlib .cbook import simple_linear_interpolation , maxdict
17
19
from matplotlib import rcParams
18
20
21
+
19
22
class Path (object ):
20
23
"""
21
24
:class:`Path` represents a series of possibly disconnected,
@@ -356,9 +359,10 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
356
359
CLOSEPOLY = self .CLOSEPOLY
357
360
STOP = self .STOP
358
361
359
- vertices , codes = cleanup_path (self , transform , remove_nans , clip ,
360
- snap , stroke_width , simplify , curves ,
361
- sketch )
362
+ vertices , codes = _path .cleanup_path (
363
+ self , transform , remove_nans , clip ,
364
+ snap , stroke_width , simplify , curves ,
365
+ sketch )
362
366
len_vertices = len (vertices )
363
367
364
368
i = 0
@@ -398,7 +402,7 @@ def contains_point(self, point, transform=None, radius=0.0):
398
402
"""
399
403
if transform is not None :
400
404
transform = transform .frozen ()
401
- result = point_in_path (point [0 ], point [1 ], radius , self , transform )
405
+ result = _path . point_in_path (point [0 ], point [1 ], radius , self , transform )
402
406
return result
403
407
404
408
def contains_points (self , points , transform = None , radius = 0.0 ):
@@ -414,7 +418,7 @@ def contains_points(self, points, transform=None, radius=0.0):
414
418
"""
415
419
if transform is not None :
416
420
transform = transform .frozen ()
417
- result = points_in_path (points , radius , self , transform )
421
+ result = _path . points_in_path (points , radius , self , transform )
418
422
return result
419
423
420
424
def contains_path (self , path , transform = None ):
@@ -426,7 +430,7 @@ def contains_path(self, path, transform=None):
426
430
"""
427
431
if transform is not None :
428
432
transform = transform .frozen ()
429
- return path_in_path (self , None , path , transform )
433
+ return _path . path_in_path (self , None , path , transform )
430
434
431
435
def get_extents (self , transform = None ):
432
436
"""
@@ -444,7 +448,7 @@ def get_extents(self, transform=None):
444
448
if not transform .is_affine :
445
449
path = self .transformed (transform )
446
450
transform = None
447
- return Bbox (get_path_extents (path , transform ))
451
+ return Bbox (_path . get_path_extents (path , transform ))
448
452
449
453
def intersects_path (self , other , filled = True ):
450
454
"""
@@ -454,7 +458,7 @@ def intersects_path(self, other, filled=True):
454
458
That is, if one path completely encloses the other,
455
459
:meth:`intersects_path` will return True.
456
460
"""
457
- return path_intersects_path (self , other , filled )
461
+ return _path . path_intersects_path (self , other , filled )
458
462
459
463
def intersects_bbox (self , bbox , filled = True ):
460
464
"""
@@ -514,7 +518,7 @@ def to_polygons(self, transform=None, width=0, height=0):
514
518
515
519
# Deal with the case where there are curves and/or multiple
516
520
# subpaths (using extension code)
517
- return convert_path_to_polygons (self , transform , width , height )
521
+ return _path . convert_path_to_polygons (self , transform , width , height )
518
522
519
523
_unit_rectangle = None
520
524
@classmethod
@@ -833,12 +837,11 @@ def clip_to_bbox(self, bbox, inside=True):
833
837
to the outside of the box.
834
838
"""
835
839
# Use make_compound_path_from_polys
836
- verts = clip_path_to_rect (self , bbox , inside )
840
+ verts = _path . clip_path_to_rect (self , bbox , inside )
837
841
paths = [Path (poly ) for poly in verts ]
838
842
return self .make_compound_path (* paths )
839
843
840
844
841
- _get_path_collection_extents = get_path_collection_extents
842
845
def get_path_collection_extents (
843
846
master_transform , paths , transforms , offsets , offset_transform ):
844
847
"""
@@ -869,9 +872,10 @@ def get_path_collection_extents(
869
872
from transforms import Bbox
870
873
if len (paths ) == 0 :
871
874
raise ValueError ("No paths provided" )
872
- return Bbox .from_extents (* _get_path_collection_extents (
875
+ return Bbox .from_extents (* _path . get_path_collection_extents (
873
876
master_transform , paths , transforms , offsets , offset_transform ))
874
877
878
+
875
879
def get_paths_extents (paths , transforms = []):
876
880
"""
877
881
Given a sequence of :class:`Path` objects and optional
@@ -887,5 +891,28 @@ def get_paths_extents(paths, transforms=[]):
887
891
from transforms import Bbox , Affine2D
888
892
if len (paths ) == 0 :
889
893
raise ValueError ("No paths provided" )
890
- return Bbox .from_extents (* _get_path_collection_extents (
894
+ return Bbox .from_extents (* _path . get_path_collection_extents (
891
895
Affine2D (), paths , transforms , [], Affine2D ()))
896
+
897
+
898
+ def _define_deprecated_functions (ns ):
899
+ from cbook import deprecated
900
+
901
+ # The C++ functions are not meant to be used directly.
902
+ # Users should use the more pythonic wrappers in the Path
903
+ # class instead.
904
+ for func , alternative in [
905
+ ('point_in_path' , 'path.Path.contains_point' ),
906
+ ('get_path_extents' , 'path.Path.get_extents' ),
907
+ ('point_in_path_collection' , 'collection.Collection.contains' ),
908
+ ('path_in_path' , 'path.Path.contains_path' ),
909
+ ('path_intersects_path' , 'path.Path.intersects_path' ),
910
+ ('convert_path_to_polygons' , 'path.Path.to_polygons' ),
911
+ ('cleanup_path' , 'path.Path.cleaned' ),
912
+ ('points_in_path' , 'path.Path.contains_points' ),
913
+ ('clip_path_to_rect' , 'path.Path.clip_to_bbox' )]:
914
+ ns [func ] = deprecated (
915
+ since = '1.3' , alternative = alternative )(getattr (_path , func ))
916
+
917
+
918
+ _define_deprecated_functions (locals ())
0 commit comments