Skip to content

Commit 213d4af

Browse files
committed
TST: Add test for plotting MultiIndex bar plot
A fix to issue #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 f072c05 commit 213d4af

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/plotting/test_frame.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,33 @@ def test_bar_numeric(self):
32883288
ticklocs = ax.xaxis.get_ticklocs()
32893289
tm.assert_numpy_array_equal(ticklocs, index)
32903290

3291+
def test_bar_multiindex(self):
3292+
# Test from pandas/doc/source/user_guide/visualization.rst
3293+
# at section Plotting With Error Bars
3294+
# Related to issue GH: 26186
3295+
3296+
ix3 = pd.MultiIndex.from_arrays(
3297+
[
3298+
["a", "a", "a", "a", "b", "b", "b", "b"],
3299+
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
3300+
],
3301+
names=["letter", "word"],
3302+
)
3303+
3304+
df3 = pd.DataFrame(
3305+
{"data1": [3, 2, 4, 3, 2, 4, 3, 2], "data2": [6, 5, 7, 5, 4, 5, 6, 5]},
3306+
index=ix3,
3307+
)
3308+
3309+
# Group by index labels and take the means and standard deviations
3310+
# for each group
3311+
gp3 = df3.groupby(level=("letter", "word"))
3312+
means = gp3.mean()
3313+
errors = gp3.std()
3314+
3315+
# No assertion we just ensure that we can plot a MultiIndex bar plot
3316+
means.plot.bar(yerr=errors, capsize=4)
3317+
32913318

32923319
def _generate_4_axes_via_gridspec():
32933320
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)