Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 425823e

Browse files
committed
Allow creating empty closed paths
1 parent dd5f241 commit 425823e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
137137
if len(codes) and codes[0] != self.MOVETO:
138138
raise ValueError("The first element of 'code' must be equal "
139139
"to 'MOVETO' ({})".format(self.MOVETO))
140-
elif closed:
140+
elif closed and len(vertices):
141141
codes = np.empty(len(vertices), dtype=self.code_type)
142142
codes[0] = self.MOVETO
143143
codes[1:-1] = self.LINETO

lib/matplotlib/tests/test_path.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from matplotlib import transforms
1313

1414

15+
def test_empty_closed_path():
16+
path = Path(np.zeros((0, 2)), closed=True)
17+
assert path.vertices.shape == (0, 2)
18+
assert path.codes is None
19+
20+
1521
def test_readonly_path():
1622
path = Path.unit_circle()
1723

0 commit comments

Comments
 (0)