Skip to content

Commit f93347b

Browse files
committed
TST: Add test for plotting MultiIndex bar plot
A fix to issue pandas-dev#26186 revealed no tests existed about plotting a bar plot for a MultiIndex, but a section of the user guide visualization did. This section of the user guide is now in the test suite.
1 parent d962220 commit f93347b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/plotting/test_frame.py

+27
Original file line numberDiff line numberDiff line change
@@ -3354,6 +3354,33 @@ def test_bar_numeric(self):
33543354
ticklocs = ax.xaxis.get_ticklocs()
33553355
tm.assert_numpy_array_equal(ticklocs, index)
33563356

3357+
def test_bar_multiindex(self):
3358+
# Test from pandas/doc/source/user_guide/visualization.rst
3359+
# at section Plotting With Error Bars
3360+
# Related to issue GH: 26186
3361+
3362+
ix3 = pd.MultiIndex.from_arrays(
3363+
[
3364+
["a", "a", "a", "a", "b", "b", "b", "b"],
3365+
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
3366+
],
3367+
names=["letter", "word"],
3368+
)
3369+
3370+
df3 = pd.DataFrame(
3371+
{"data1": [3, 2, 4, 3, 2, 4, 3, 2], "data2": [6, 5, 7, 5, 4, 5, 6, 5]},
3372+
index=ix3,
3373+
)
3374+
3375+
# Group by index labels and take the means and standard deviations
3376+
# for each group
3377+
gp3 = df3.groupby(level=("letter", "word"))
3378+
means = gp3.mean()
3379+
errors = gp3.std()
3380+
3381+
# No assertion we just ensure that we can plot a MultiIndex bar plot
3382+
means.plot.bar(yerr=errors, capsize=4)
3383+
33573384

33583385
def _generate_4_axes_via_gridspec():
33593386
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)