A series of possibly disconnected, possibly closed, line and curve
segments.
The underlying storage is made up of two parallel numpy arrays:
vertices: an (N, 2) float array of vertices
codes: an N-length numpy.uint8 array of path codes, or None
These two arrays always have the same length in the first
dimension. For example, to represent a cubic curve, you must
provide three vertices and three CURVE4 codes.
Draw a line from the current position to the given vertex.
If codes is None, it is interpreted as a MOVETO followed by a series
of LINETO.
Users of Path objects should not access the vertices and codes arrays
directly. Instead, they should use iter_segments or cleaned to get the
vertex/code pairs. This helps, in particular, to consistently handle the
case of codes being None.
Some behavior of Path objects can be controlled by rcParams. See the
rcParams whose keys start with 'path.'.
Create a new path with the given vertices and codes.
Parameters:
vertices : (N, 2) array-like
The path vertices, as an array, masked array or sequence of pairs.
Masked values, if any, will be converted to NaNs, which are then
handled correctly by the Agg PathIterator and other consumers of
path data, such as iter_segments().
codes : array-like or None, optional
N-length array of integers representing the codes of the path.
If not None, codes must be the same length as vertices.
If None, vertices will be treated as a series of line segments.
_interpolation_steps : int, optional
Used as a hint to certain projections, such as Polar, that this
path should be linearly interpolated immediately before drawing.
This attribute is primarily an implementation detail and is not
intended for public use.
closed : bool, optional
If is None and closed is True, vertices will be treated as
line segments of a closed polygon. Note that the last vertex will
then be ignored (as the corresponding code will be set to
).
Return a Path for the unit circle arc from angles theta1 to
theta2 (in degrees).
theta2 is unwrapped to produce the shortest arc within 360 degrees.
That is, if theta2 > theta1 + 360, the arc will be from theta1 to
theta2 - 360 and not a full circle plus some extra overlap.
As a special case, if the span theta2 - theta1 is within
floating-point tolerance of a whole number of turns, a complete circle
is drawn.
If n is provided, it is the number of spline segments to make.
If is not provided, the number of spline segments is
determined based on the delta between and .
Each code is one of STOP, MOVETO, LINETO, CURVE3, or
. For codes that correspond to more than one vertex
( and ), that code will be repeated so that the length
of and is always the same.
contains_path(path, transform=None)
Return whether this (closed) path completely contains the given path.
If transform is not None, the path will be transformed before
checking for containment.
contains_point(point, transform=None, radius=0.0)
Return whether the area enclosed by the path contains the given point.
The path is always treated as closed; i.e. if the last code is not
CLOSEPOLY an implicit segment connecting the last vertex to the first
vertex is assumed.
Return whether the area enclosed by the path contains the given points.
The path is always treated as closed; i.e. if the last code is not
CLOSEPOLY an implicit segment connecting the last vertex to the first
vertex is assumed.
Parameters:
points : (N, 2) array
The points to check. Columns contain x and y values.
copy()
Return a shallow copy of the Path, which will share the
vertices and codes with the source Path.
deepcopy(memo=None)
Return a deep copy of the Path. The Path will not be readonly,
even if the source Path is.
Transform to apply to path before computing extents, if any.
**kwargs
Forwarded to .
statichatch(hatchpattern, density=6)
Given a hatch specifier, hatchpattern, generates a Path that
can be used in a repeated hatching pattern. density is the
number of lines per unit square.
interpolated(steps)
Return a new path with each segment divided into steps parts.
Convert this path to a list of polygons or polylines. Each
polygon/polyline is an (N, 2) array of vertices. In other words,
each polygon has no MOVETO instructions or curves. This
is useful for displaying in backends that do not support
compound paths or Bézier curves.
If width and height are both non-zero then the lines will
be simplified so that vertices outside of (0, 0), (width,
height) will be clipped.
The resulting polygons will be simplified if the
attribute of the path is .
Return a Path for the unit circle wedge from angles theta1 to
theta2 (in degrees).
theta2 is unwrapped to produce the shortest wedge within 360 degrees.
That is, if theta2 > theta1 + 360, the wedge will be from theta1
to theta2 - 360 and not a full circle plus some extra overlap.
If n is provided, it is the number of spline segments to make.
If n is not provided, the number of spline segments is
determined based on the delta between theta1 and theta2.
That is, given a sequence of Paths, Transforms objects, and offsets, as found
in a PathCollection, return the bounding box that encapsulates all of them.
The way that paths, transforms and offsets are combined follows the same
method as for collections: each is iterated over independently, so if you have 3
paths (A, B, C), 2 transforms (α, β) and 1 offset (O), their combinations are as
follows:
(A, α, O)
(B, β, O)
(C, α, O)
CURVE3
: 1 control point, 1 endpoint
Draw a quadratic Bézier curve from the current position, with the given
control point, to the given end point.
If not None, point will be compared to self transformed
by transform; i.e. for a correct check, transform should
transform the path into the coordinate system of point.
radius : float, default: 0
Additional margin on the path in coordinates of point.
The path is extended tangentially by radius/2; i.e. if you would
draw the path with a linewidth of radius, all points on the line
would still be considered to be contained in the area. Conversely,
negative values shrink the area: Points on the imaginary line
will be considered outside the area.
Returns:
bool
Notes
The current algorithm has some limitations:
The result is undefined for points exactly at the boundary
(i.e. at the path shifted by radius/2).
The result is undefined if there is no enclosed area, i.e. all
vertices are on a straight line.
If bounding lines start to cross each other due to radius shift,
the result is not guaranteed to be correct.
If not None, points will be compared to self transformed
by transform; i.e. for a correct check, transform should
transform the path into the coordinate system of points.
radius : float, default: 0
Additional margin on the path in coordinates of points.
The path is extended tangentially by radius/2; i.e. if you would
draw the path with a linewidth of radius, all points on the line
would still be considered to be contained in the area. Conversely,
negative values shrink the area: Points on the imaginary line
will be considered outside the area.
Returns:
length-N bool array
Notes
The current algorithm has some limitations:
The result is undefined for points exactly at the boundary
(i.e. at the path shifted by radius/2).
The result is undefined if there is no enclosed area, i.e. all
vertices are on a straight line.
If bounding lines start to cross each other due to radius shift,
the result is not guaranteed to be correct.
The Bézier curves that make up the current path. Note in particular
that freestanding points are Bézier curves of order 0, and lines
are Bézier curves of order 1 (with two control points).
The code describing what kind of curve is being returned.
MOVETO, LINETO, CURVE3, and CURVE4 correspond to
Bézier curves with 1, 2, 3, and 4 control points (respectively).
CLOSEPOLY is a LINETO with the control points correctly
chosen based on the start/end points of the current stroke.
Iterate over all curve segments in the path.
Each iteration returns a pair (vertices,code), where vertices
is a sequence of 1-3 coordinate pairs, and code is a Path code.
Additionally, this method can provide a number of standard cleanups and
conversions to the path.
If not None, the given affine transformation will be applied to the
path.
remove_nans : bool, optional
Whether to remove all NaNs from the path and skip over them using
MOVETO commands.
clip : None or (float, float, float, float), optional
If not None, must be a four-tuple (x1, y1, x2, y2)
defining a rectangle in which to clip the path.
snap : None or bool, optional
If True, snap all nodes to pixels; if False, don't snap them.
If None, snap if the path contains only segments
parallel to the x or y axes, and no more than 1024 of them.
stroke_width : float, optional
The width of the stroke being drawn (used for path snapping).
If closed_only is True (default), only closed polygons,
with the last point being the same as the first point, will be
returned. Any unclosed polylines in the path will be
explicitly closed. If closed_only is False, any unclosed
polygons in the path will be returned as unclosed polygons,
and the closed polygons will be returned explicitly closed by
setting the last point to the same as the first point.