Skip to content

Commit d9aa5f6

Browse files
committed
Add test for grouped_bar() return value
1 parent a4ed768 commit d9aa5f6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, bar_containers):
7878
self.bar_containers = bar_containers
7979

8080
def remove(self):
81-
[b.remove() for b in self.bars]
81+
[b.remove() for b in self.bar_containers]
8282

8383

8484
@_docstring.interpd

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from matplotlib import rc_context, patheffects
2424
import matplotlib.colors as mcolors
2525
import matplotlib.dates as mdates
26+
from matplotlib.container import BarContainer
2627
from matplotlib.figure import Figure
2728
from matplotlib.axes import Axes
2829
from matplotlib.lines import Line2D
@@ -2251,6 +2252,20 @@ def test_grouped_bar_dataframe(fig_test, fig_ref, pd):
22512252
ax.legend()
22522253

22532254

2255+
def test_grouped_bar_return_value():
2256+
fig, ax = plt.subplots()
2257+
ret = ax.grouped_bar([[1, 2, 3], [11, 12, 13]], tick_labels=['A', 'B', 'C'])
2258+
2259+
assert len(ret.bar_containers) == 2
2260+
for bc in ret.bar_containers:
2261+
assert isinstance(bc, BarContainer)
2262+
assert bc in ax.containers
2263+
2264+
ret.remove()
2265+
for bc in ret.bar_containers:
2266+
assert bc not in ax.containers
2267+
2268+
22542269
def test_boxplot_dates_pandas(pd):
22552270
# smoke test for boxplot and dates in pandas
22562271
data = np.random.rand(5, 2)

0 commit comments

Comments
 (0)