Skip to content

Commit

Permalink
Allow non 2D paths [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsonTran committed Apr 30, 2024
1 parent 04bda58 commit ef0c3e5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ class Path:
CLOSEPOLY: 1}

def __init__(self, vertices, codes=None, _interpolation_steps=1,
closed=False, readonly=False):
closed=False, readonly=False, dims=2):
"""
Create a new path with the given vertices and codes.
Parameters
----------
vertices : (N, 2) array-like
vertices : (N, dims) 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
Expand All @@ -125,9 +125,14 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
readonly : bool, optional
Makes the path behave in an immutable way and sets the vertices
and codes as read-only arrays.
dims : int, optional
"""
if dims <= 1:
raise ValueError("Path must be at least 2D")
self._dims = dims

vertices = _to_unmasked_float_array(vertices)
_api.check_shape((None, 2), vertices=vertices)
_api.check_shape((None, dims), vertices=vertices)

if codes is not None:
codes = np.asarray(codes, self.code_type)
Expand Down Expand Up @@ -160,7 +165,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
self._readonly = False

@classmethod
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None, dims=2):
"""
Create a Path instance without the expense of calling the constructor.
Expand All @@ -178,6 +183,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
pth._vertices = _to_unmasked_float_array(verts)
pth._codes = codes
pth._readonly = False
pth._dims = dims
if internals_from is not None:
pth._should_simplify = internals_from._should_simplify
pth._simplify_threshold = internals_from._simplify_threshold
Expand Down Expand Up @@ -210,7 +216,7 @@ def _update_values(self):

@property
def vertices(self):
"""The vertices of the `Path` as an (N, 2) array."""
"""The vertices of the `Path` as an (N, dims) array."""
return self._vertices

@vertices.setter
Expand Down

0 comments on commit ef0c3e5

Please sign in to comment.