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

Skip to content

Commit 9edcb03

Browse files
authored
Merge pull request #7801 from samsontmr/fix-#7784
FIX: Add short-circuit return to matplotlib.artist.setp if input is length 0
2 parents a02e303 + 193da2e commit 9edcb03

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/matplotlib/artist.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,9 @@ def setp(obj, *args, **kwargs):
14271427
else:
14281428
objs = list(cbook.flatten(obj))
14291429

1430+
if not objs:
1431+
return
1432+
14301433
insp = ArtistInspector(objs[0])
14311434

14321435
# file has to be popped before checking if kwargs is empty

lib/matplotlib/tests/test_artist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ def test_properties():
239239

240240
@cleanup
241241
def test_setp():
242+
# Check empty list
243+
plt.setp([])
244+
plt.setp([[]])
245+
242246
# Check arbitrary iterables
243247
fig, axes = plt.subplots()
244248
lines1 = axes.plot(range(3))

0 commit comments

Comments
 (0)