Skip to content

Commit a802e31

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 8230467 commit a802e31

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
@@ -3388,6 +3388,33 @@ def test_bar_numeric(self):
33883388
ticklocs = ax.xaxis.get_ticklocs()
33893389
tm.assert_numpy_array_equal(ticklocs, index)
33903390

3391+
def test_bar_multiindex(self):
3392+
# Test from pandas/doc/source/user_guide/visualization.rst
3393+
# at section Plotting With Error Bars
3394+
# Related to issue GH: 26186
3395+
3396+
ix3 = pd.MultiIndex.from_arrays(
3397+
[
3398+
["a", "a", "a", "a", "b", "b", "b", "b"],
3399+
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
3400+
],
3401+
names=["letter", "word"],
3402+
)
3403+
3404+
df3 = pd.DataFrame(
3405+
{"data1": [3, 2, 4, 3, 2, 4, 3, 2], "data2": [6, 5, 7, 5, 4, 5, 6, 5]},
3406+
index=ix3,
3407+
)
3408+
3409+
# Group by index labels and take the means and standard deviations
3410+
# for each group
3411+
gp3 = df3.groupby(level=("letter", "word"))
3412+
means = gp3.mean()
3413+
errors = gp3.std()
3414+
3415+
# No assertion we just ensure that we can plot a MultiIndex bar plot
3416+
means.plot.bar(yerr=errors, capsize=4)
3417+
33913418

33923419
def _generate_4_axes_via_gridspec():
33933420
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)