Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef0c3e5

Browse filesBrowse files
committed
Allow non 2D paths [skip ci]
1 parent 04bda58 commit ef0c3e5
Copy full SHA for ef0c3e5

File tree

1 file changed

+11
-5
lines changed
Filter options

1 file changed

+11
-5
lines changed

‎lib/matplotlib/path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/path.py
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ class Path:
9797
CLOSEPOLY: 1}
9898

9999
def __init__(self, vertices, codes=None, _interpolation_steps=1,
100-
closed=False, readonly=False):
100+
closed=False, readonly=False, dims=2):
101101
"""
102102
Create a new path with the given vertices and codes.
103103
104104
Parameters
105105
----------
106-
vertices : (N, 2) array-like
106+
vertices : (N, dims) array-like
107107
The path vertices, as an array, masked array or sequence of pairs.
108108
Masked values, if any, will be converted to NaNs, which are then
109109
handled correctly by the Agg PathIterator and other consumers of
@@ -125,9 +125,14 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
125125
readonly : bool, optional
126126
Makes the path behave in an immutable way and sets the vertices
127127
and codes as read-only arrays.
128+
dims : int, optional
128129
"""
130+
if dims <= 1:
131+
raise ValueError("Path must be at least 2D")
132+
self._dims = dims
133+
129134
vertices = _to_unmasked_float_array(vertices)
130-
_api.check_shape((None, 2), vertices=vertices)
135+
_api.check_shape((None, dims), vertices=vertices)
131136

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

162167
@classmethod
163-
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
168+
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None, dims=2):
164169
"""
165170
Create a Path instance without the expense of calling the constructor.
166171
@@ -178,6 +183,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
178183
pth._vertices = _to_unmasked_float_array(verts)
179184
pth._codes = codes
180185
pth._readonly = False
186+
pth._dims = dims
181187
if internals_from is not None:
182188
pth._should_simplify = internals_from._should_simplify
183189
pth._simplify_threshold = internals_from._simplify_threshold
@@ -210,7 +216,7 @@ def _update_values(self):
210216

211217
@property
212218
def vertices(self):
213-
"""The vertices of the `Path` as an (N, 2) array."""
219+
"""The vertices of the `Path` as an (N, dims) array."""
214220
return self._vertices
215221

216222
@vertices.setter

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.