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

Skip to content

Commit 5a43452

Browse files
Merge pull request #29401 from rcomer/errorbar-remove
FIX: add errorbars with `add_container`
2 parents 147ddab + a39e2d6 commit 5a43452

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3853,7 +3853,7 @@ def apply_mask(arrays, mask):
38533853
(data_line, tuple(caplines), tuple(barcols)),
38543854
has_xerr=(xerr is not None), has_yerr=(yerr is not None),
38553855
label=label)
3856-
self.containers.append(errorbar_container)
3856+
self.add_container(errorbar_container)
38573857

38583858
return errorbar_container # (l0, caplines, barcols)
38593859

lib/matplotlib/tests/test_axes.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4274,6 +4274,24 @@ def test_errorbar_nonefmt():
42744274
assert np.all(errbar.get_color() == mcolors.to_rgba('C0'))
42754275

42764276

4277+
def test_errorbar_remove():
4278+
x = np.arange(5)
4279+
y = np.arange(5)
4280+
4281+
fig, ax = plt.subplots()
4282+
ec = ax.errorbar(x, y, xerr=1, yerr=1)
4283+
4284+
assert len(ax.containers) == 1
4285+
assert len(ax.lines) == 5
4286+
assert len(ax.collections) == 2
4287+
4288+
ec.remove()
4289+
4290+
assert not ax.containers
4291+
assert not ax.lines
4292+
assert not ax.collections
4293+
4294+
42774295
def test_errorbar_line_specific_kwargs():
42784296
# Check that passing line-specific keyword arguments will not result in
42794297
# errors.

0 commit comments

Comments
 (0)