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

Skip to content

Commit 2a0cd72

Browse files
Merge pull request #29408 from meeseeksmachine/auto-backport-of-pr-29401-on-v3.10.x
Backport PR #29401 on branch v3.10.x (FIX: add errorbars with `add_container`)
2 parents ba332c0 + c94a469 commit 2a0cd72

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
@@ -3861,7 +3861,7 @@ def apply_mask(arrays, mask):
38613861
(data_line, tuple(caplines), tuple(barcols)),
38623862
has_xerr=(xerr is not None), has_yerr=(yerr is not None),
38633863
label=label)
3864-
self.containers.append(errorbar_container)
3864+
self.add_container(errorbar_container)
38653865

38663866
return errorbar_container # (l0, caplines, barcols)
38673867

lib/matplotlib/tests/test_axes.py

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

42274227

4228+
def test_errorbar_remove():
4229+
x = np.arange(5)
4230+
y = np.arange(5)
4231+
4232+
fig, ax = plt.subplots()
4233+
ec = ax.errorbar(x, y, xerr=1, yerr=1)
4234+
4235+
assert len(ax.containers) == 1
4236+
assert len(ax.lines) == 5
4237+
assert len(ax.collections) == 2
4238+
4239+
ec.remove()
4240+
4241+
assert not ax.containers
4242+
assert not ax.lines
4243+
assert not ax.collections
4244+
4245+
42284246
def test_errorbar_line_specific_kwargs():
42294247
# Check that passing line-specific keyword arguments will not result in
42304248
# errors.

0 commit comments

Comments
 (0)