Text of matplotlib.org › stable › api › path_api.html as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

matplotlib.path — Matplotlib 3.11.2 documentation

Skip to main content Plot types User guide Tutorials Examples Reference Contribute Releases Gitter Discourse GitHub matplotlib.path # A module for dealing with the polylines used throughout Matplotlib. The primary class for polyline handling in Matplotlib is Path . Almost all vector drawing makes use of Path s somewhere in the drawing pipeline. Whilst a Path instance itself cannot be drawn, some Artist subclasses, such as PathPatch and PathCollection , can be used for convenient Path visualisation. class matplotlib.path.

Path ( vertices , codes = None , _interpolation_steps = 1 , closed = False , readonly = False ) [source] # Bases: object 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. The code types are: STOP 1 vertex (ignored) A marker for the end of the entire path (currently not required and ignored) MOVETO 1 vertex Pick up the pen and move to the given vertex. LINETO 1 vertex Draw a line from the current position to the given vertex. 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.

CURVE4 2 control points, 1 endpoint Draw a cubic Bézier curve from the current position, with the given control points, to the given end point. CLOSEPOLY 1 vertex (ignored) Draw a line segment to the start point of the current polyline. 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.'. Note The vertices and codes arrays should be treated as immutable -- there are a number of optimizations and assumptions made up front in the constructor that will not change when the data changes. 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 codes 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 CLOSEPOLY ). readonly bool, optional Makes the path behave in an immutable way and sets the vertices and codes as read-only arrays. CLOSEPOLY = np.uint8(79) # CURVE3 = np.uint8(3) # CURVE4 = np.uint8(4) # LINETO = np.uint8(2) # MOVETO = np.uint8(1) # NUM_VERTICES_FOR_CODE = {np.uint8(0): 1, np.uint8(1): 1, np.uint8(2): 1, np.uint8(3): 2, np.uint8(4): 3, np.uint8(79): 1} # A dictionary mapping Path codes to the number of vertices that the code expects.

STOP = np.uint8(0) # classmethod arc ( theta1 , theta2 , n = None , is_wedge = False ) [source] # 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 n is not provided, the number of spline segments is determined based on the delta between theta1 and theta2 . Masionobe, L. 2003. Drawing an elliptical arc using polylines, quadratic or cubic Bezier curves . classmethod circle ( center = (0.0, 0.0) , radius = 1.0 , readonly = False ) [source] # Return a Path representing a circle of a given radius and center.

Parameters : center (float, float), default: (0, 0) The center of the circle. radius float, default: 1 The radius of the circle. readonly bool Whether the created path should have the "readonly" argument set when creating the Path instance. Notes The circle is approximated using 8 cubic Bézier curves, as described in Lancaster, Don. Approximating a Circle or an Ellipse Using Four Bezier Cubic Splines . cleaned ( transform = None , remove_nans = False , clip = None , * , simplify = False , curves = False , stroke_width = 1.0 , snap = False , sketch = None ) [source] # Return a new Path with vertices and codes cleaned according to the parameters.

See also Path.iter_segments for details of the keyword arguments. clip_to_bbox ( bbox , inside = True ) [source] # Clip the path to the given bounding box. The path must be made up of one or more closed polygons. This algorithm will not behave correctly for unclosed paths. If inside is True , clip to the inside of the box, otherwise to the outside of the box. code_type # alias of uint8 property codes # The list of codes in the Path as a 1D array.

Each code is one of STOP , MOVETO , LINETO , CURVE3 , CURVE4 or CLOSEPOLY . For codes that correspond to more than one vertex ( CURVE3 and CURVE4 ), that code will be repeated so that the length of vertices and codes is always the same. contains_path ( path , transform = None ) [source] # 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 ) [source] # 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. Parameters : point (float, float) The point (x, y) to check. transform Transform , optional 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. contains_points ( points , transform = None , radius = 0.0 ) [source] # 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. transform Tran

The rest of this page is on the live site.