14
14
15
15
import numpy as np
16
16
17
- from . import _path , rcParams
17
+ from . import _path , cbook , rcParams
18
18
from .cbook import _to_unmasked_float_array , simple_linear_interpolation
19
19
20
20
@@ -359,46 +359,41 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
359
359
snap = False , stroke_width = 1.0 , simplify = None ,
360
360
curves = True , sketch = None ):
361
361
"""
362
- Iterates over all of the curve segments in the path. Each
363
- iteration returns a 2-tuple (*vertices*, *code*), where
364
- *vertices* is a sequence of 1 - 3 coordinate pairs, and *code* is
365
- one of the :class:`Path` codes.
362
+ Iterates over all of the curve segments in the path. Each iteration
363
+ returns a 2-tuple ``(vertices, code)``, where ``vertices`` is a
364
+ sequence of 1-3 coordinate pairs, and ``code`` is a `Path` code.
366
365
367
- Additionally, this method can provide a number of standard
368
- cleanups and conversions to the path.
366
+ Additionally, this method can provide a number of standard cleanups and
367
+ conversions to the path.
369
368
370
369
Parameters
371
370
----------
372
- transform : None or :class:`~matplotlib.transforms.Transform` instance
373
- If not None, the given affine transformation will
374
- be applied to the path.
375
- remove_nans : {False, True} , optional
376
- If True, will remove all NaNs from the path and
377
- insert MOVETO commands to skip over them .
378
- clip : None or sequence , optional
371
+ transform : None or :class:`~matplotlib.transforms.Transform`
372
+ If not None, the given affine transformation will be applied to the
373
+ path.
374
+ remove_nans : bool , optional
375
+ Whether to remove all NaNs from the path and skip over them using
376
+ MOVETO commands.
377
+ clip : None or (float, float, float, float) , optional
379
378
If not None, must be a four-tuple (x1, y1, x2, y2)
380
379
defining a rectangle in which to clip the path.
381
380
snap : None or bool, optional
382
- If None, auto- snap to pixels, to reduce
383
- fuzziness of rectilinear lines. If True, force snapping, and
384
- if False, don't snap .
381
+ If True, snap all nodes to pixels; if False, don't snap them.
382
+ If None, perform snapping if the path contains only segments
383
+ parallel to the x or y axes, and no more than 1024 of them .
385
384
stroke_width : float, optional
386
- The width of the stroke being drawn. Needed
387
- as a hint for the snapping algorithm.
385
+ The width of the stroke being drawn (used for path snapping).
388
386
simplify : None or bool, optional
389
- If True, perform simplification, to remove
390
- vertices that do not affect the appearance of the path. If
391
- False, perform no simplification. If None, use the
392
- should_simplify member variable. See also the rcParams
393
- path.simplify and path.simplify_threshold.
394
- curves : {True, False}, optional
395
- If True, curve segments will be returned as curve
396
- segments. If False, all curves will be converted to line
397
- segments.
387
+ Whether to simplify the path by removing vertices
388
+ that do not affect its appearance. If None, use the
389
+ :attr:`should_simplify` attribute. See also :rc:`path.simplify`
390
+ and :rc:`path.simplify_threshold`.
391
+ curves : bool, optional
392
+ If True, curve segments will be returned as curve segments.
393
+ If False, all curves will be converted to line segments.
398
394
sketch : None or sequence, optional
399
395
If not None, must be a 3-tuple of the form
400
- (scale, length, randomness), representing the sketch
401
- parameters.
396
+ (scale, length, randomness), representing the sketch parameters.
402
397
"""
403
398
if not len (self ):
404
399
return
@@ -441,7 +436,6 @@ def cleaned(self, transform=None, remove_nans=False, clip=None,
441
436
Returns
442
437
-------
443
438
Path instance with cleaned up vertices and codes.
444
-
445
439
"""
446
440
vertices , codes = _path .cleanup_path (self , transform ,
447
441
remove_nans , clip ,
@@ -621,8 +615,7 @@ def to_polygons(self, transform=None, width=0, height=0, closed_only=True):
621
615
@classmethod
622
616
def unit_rectangle (cls ):
623
617
"""
624
- Return a :class:`Path` instance of the unit rectangle
625
- from (0, 0) to (1, 1).
618
+ Return a `Path` instance of the unit rectangle from (0, 0) to (1, 1).
626
619
"""
627
620
if cls ._unit_rectangle is None :
628
621
cls ._unit_rectangle = \
@@ -706,7 +699,6 @@ def unit_circle(cls):
706
699
Return the readonly :class:`Path` of the unit circle.
707
700
708
701
For most cases, :func:`Path.circle` will be what you want.
709
-
710
702
"""
711
703
if cls ._unit_circle is None :
712
704
cls ._unit_circle = cls .circle (center = (0 , 0 ), radius = 1 ,
@@ -716,7 +708,7 @@ def unit_circle(cls):
716
708
@classmethod
717
709
def circle (cls , center = (0. , 0. ), radius = 1. , readonly = False ):
718
710
"""
719
- Return a Path representing a circle of a given radius and center.
711
+ Return a ` Path` representing a circle of a given radius and center.
720
712
721
713
Parameters
722
714
----------
@@ -730,13 +722,10 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False):
730
722
731
723
Notes
732
724
-----
733
- The circle is approximated using cubic Bezier curves. This
734
- uses 8 splines around the circle using the approach presented
735
- here:
725
+ The circle is approximated using 8 cubic Bezier curves, as decribed in
736
726
737
727
Lancaster, Don. `Approximating a Circle or an Ellipse Using Four
738
728
Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_.
739
-
740
729
"""
741
730
MAGIC = 0.2652031
742
731
SQRTHALF = np .sqrt (0.5 )
@@ -789,13 +778,9 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False):
789
778
@classmethod
790
779
def unit_circle_righthalf (cls ):
791
780
"""
792
- Return a :class:`Path` of the right half
793
- of a unit circle. The circle is approximated using cubic Bezier
794
- curves. This uses 4 splines around the circle using the approach
795
- presented here:
781
+ Return a `Path` of the right half of a unit circle.
796
782
797
- Lancaster, Don. `Approximating a Circle or an Ellipse Using Four
798
- Bezier Cubic Splines <http://www.tinaja.com/glib/ellipse4.pdf>`_.
783
+ See `Path.circle` for the reference on the approximation used.
799
784
"""
800
785
if cls ._unit_circle_righthalf is None :
801
786
MAGIC = 0.2652031
@@ -835,8 +820,8 @@ def unit_circle_righthalf(cls):
835
820
@classmethod
836
821
def arc (cls , theta1 , theta2 , n = None , is_wedge = False ):
837
822
"""
838
- Return an arc on the unit circle from angle
839
- *theta1* to angle *theta2* (in degrees).
823
+ Return the unit circle arc from angles *theta1* to *theta2* (in
824
+ degrees).
840
825
841
826
*theta2* is unwrapped to produce the shortest arc within 360 degrees.
842
827
That is, if *theta2* > *theta1* + 360, the arc will be from *theta1* to
@@ -914,8 +899,8 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False):
914
899
@classmethod
915
900
def wedge (cls , theta1 , theta2 , n = None ):
916
901
"""
917
- Return a wedge of the unit circle from angle
918
- *theta1* to angle *theta2* (in degrees).
902
+ Return the unit circle wedge from angles *theta1* to *theta2* (in
903
+ degrees).
919
904
920
905
*theta2* is unwrapped to produce the shortest wedge within 360 degrees.
921
906
That is, if *theta2* > *theta1* + 360, the wedge will be from *theta1*
@@ -924,6 +909,8 @@ def wedge(cls, theta1, theta2, n=None):
924
909
If *n* is provided, it is the number of spline segments to make.
925
910
If *n* is not provided, the number of spline segments is
926
911
determined based on the delta between *theta1* and *theta2*.
912
+
913
+ See `Path.arc` for the reference on the approximation used.
927
914
"""
928
915
return cls .arc (theta1 , theta2 , n , True )
929
916
@@ -957,26 +944,25 @@ def clip_to_bbox(self, bbox, inside=True):
957
944
958
945
def get_path_collection_extents (
959
946
master_transform , paths , transforms , offsets , offset_transform ):
960
- """
961
- Given a sequence of :class:`Path` objects,
962
- :class:`~matplotlib.transforms.Transform` objects and offsets, as
963
- found in a :class:`~matplotlib.collections.PathCollection`,
964
- returns the bounding box that encapsulates all of them.
965
-
966
- *master_transform* is a global transformation to apply to all paths
967
-
968
- *paths* is a sequence of :class:`Path` instances.
969
-
970
- *transforms* is a sequence of
971
- :class:`~matplotlib.transforms.Affine2D` instances.
972
-
973
- *offsets* is a sequence of (x, y) offsets (or an Nx2 array)
974
-
975
- *offset_transform* is a :class:`~matplotlib.transforms.Affine2D`
976
- to apply to the offsets before applying the offset to the path.
977
-
947
+ r"""
948
+ Given a sequence of `Path`\s, `~.Transform`\s objects, and offsets, as
949
+ found in a `~.PathCollection`, returns the bounding box that encapsulates
950
+ all of them.
951
+
952
+ Parameters
953
+ ----------
954
+ master_transform : `~.Transform`
955
+ Global transformation applied to all paths.
956
+ paths : list of `Path`
957
+ transform : list of `~.Affine2D`
958
+ offsets : (N, 2) array-like
959
+ offset_transform : `~.Affine2D`
960
+ Transform applied to the offsets before offsetting the path.
961
+
962
+ Notes
963
+ -----
978
964
The way that *paths*, *transforms* and *offsets* are combined
979
- follows the same method as for collections. Each is iterated over
965
+ follows the same method as for collections: Each is iterated over
980
966
independently, so if you have 3 paths, 2 transforms and 1 offset,
981
967
their combinations are as follows:
982
968
@@ -990,6 +976,7 @@ def get_path_collection_extents(
990
976
offsets , offset_transform ))
991
977
992
978
979
+ @cbook .deprecated ("3.1" , alternative = "get_paths_collection_extents" )
993
980
def get_paths_extents (paths , transforms = []):
994
981
"""
995
982
Given a sequence of :class:`Path` objects and optional
0 commit comments