8000 Merge pull request #20480 from anntzer/emptypolystr · matplotlib/matplotlib@7f2288b · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f2288b

Browse files
authored
Merge pull request #20480 from anntzer/emptypolystr
Fix str of empty polygon.
2 parents 0877fd7 + 1fb46d1 commit 7f2288b

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/matplotlib/patches.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,11 @@ class Polygon(Patch):
10561056
"""A general polygon patch."""
10571057

10581058
def __str__(self):
1059-
s = "Polygon%d((%g, %g) ...)"
1060-
return s % (len(self._path.vertices), *tuple(self._path.vertices[0]))
1059+
if len(self._path.vertices):
1060+
s = "Polygon%d((%g, %g) ...)"
1061+
return s % (len(self._path.vertices), *self._path.vertices[0])
1062+
else:
1063+
return "Polygon0()"
10611064

10621065
@docstring.dedent_interpd
10631066
def __init__(self, xy, closed=True, **kwargs):

lib/matplotlib/tests/test_patches.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ def test_patch_str():
373373
p = mpatches.PathPatch(path)
374374
assert str(p) == "PathPatch3((1, 2) ...)"
375375

376+
p = mpatches.Polygon(np.empty((0, 2)))
377+
assert str(p) == "Polygon0()"
378+
376379
data = [[1, 2], [2, 2], [1, 2]]
377380
p = mpatches.Polygon(data)
378381
assert str(p) == "Polygon3((1, 2) ...)"

0 commit comments

Comments
 (0)
0