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

Skip to content

Commit 7f40b09

Browse files
authored
Merge pull request matplotlib#9009 from astrofrog/fix-errorbar-remove
BUG: fix .remove method for container when one of the items is None
2 parents fa005e4 + 994076f commit 7f40b09

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ def flatten(seq, scalarp=is_scalar_or_string):
655655
and Recipe 1.12 in cookbook
656656
"""
657657
for item in seq:
658-
if scalarp(item):
658+
if scalarp(item) or item is None:
659659
yield item
660660
else:
661661
for subitem in flatten(item, scalarp):

lib/matplotlib/container.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def set_remove_method(self, f):
3434
def remove(self):
3535
for c in cbook.flatten(
3636
self, scalarp=lambda x: isinstance(x, martist.Artist)):
37-
c.remove()
37+
if c is not None:
38+
c.remove()
3839

3940
if self._remove_method:
4041
self._remove_method(self)

lib/matplotlib/tests/test_container.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,26 @@ def test_stem_remove():
99
ax = plt.gca()
1010
st = ax.stem([1, 2], [1, 2])
1111
st.remove()
12+
13+
14+
def test_errorbar_remove():
15+
16+
# Regression test for a bug that caused remove to fail when using
17+
# fmt='none'
18+
19+
ax = plt.gca()
20+
21+
eb = ax.errorbar([1], [1])
22+
eb.remove()
23+
24+
eb = ax.errorbar([1], [1], xerr=1)
25+
eb.remove()
26+
27+
eb = ax.errorbar([1], [1], yerr=2)
28+
eb.remove()
29+
30+
eb = ax.errorbar([1], [1], xerr=[2], yerr=2)
31+
eb.remove()
32+
33+
eb = ax.errorbar([1], [1], fmt='none')
34+
eb.remove()

0 commit comments

Comments
 (0)