8000 Merge pull request #20483 from meeseeksmachine/auto-backport-of-pr-20… · matplotlib/matplotlib@df9fa06 · GitHub
[go: up one dir, main page]

Skip to content

Commit df9fa06

Browse files
authored
Merge pull request #20483 from meeseeksmachine/auto-backport-of-pr-20480-on-v3.4.x
Backport PR #20480 on branch v3.4.x (Fix str of empty polygon.)
2 parents 0580c0d + c7f2f42 commit df9fa06

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
@@ -1048,8 +1048,11 @@ class Polygon(Patch):
10481048
"""A general polygon patch."""
10491049

10501050
def __str__(self):
1051-
s = "Polygon%d((%g, %g) ...)"
1052-
return s % (len(self._path.vertices), *tuple(self._path.vertices[0]))
1051+
if len(self._path.vertices):
1052+
s = "Polygon%d((%g, %g) ...)"
1053+
return s % (len(self._path.vertices), *self._path.vertices[0])
1054+
else:
1055+
return "Polygon0()"
10531056

10541057
@docstring.dedent_interpd
10551058
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
@@ -347,6 +347,9 @@ def test_patch_str():
347347
p = mpatches.PathPatch(path)
348348
assert str(p) == "PathPatch3((1, 2) ...)"
349349

350+
p = mpatches.Polygon(np.empty((0, 2)))
351+
assert str(p) == "Polygon0()"
352+
350353
data = [[1, 2], [2, 2], [1, 2]]
351354
p = mpatches.Polygon(data)
352355
assert str(p) == "Polygon3((1, 2) ...)"

0 commit comments

Comments
 (0)
0