Skip to content

Commit a9956db

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 6bbaa29 commit a9956db

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
@@ -3401,6 +3401,33 @@ def test_bar_numeric(self):
34013401
ticklocs = ax.xaxis.get_ticklocs()
34023402
tm.assert_numpy_array_equal(ticklocs, index)
34033403

3404+
def test_bar_multiindex(self):
3405+
# Test from pandas/doc/source/user_guide/visualization.rst
3406+
# at section Plotting With Error Bars
3407+
# Related to issue GH: 26186
3408+
3409+
ix3 = pd.MultiIndex.from_arrays(
3410+
[
3411+
["a", "a", "a", "a", "b", "b", "b", "b"],
3412+
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
3413+
],
3414+
names=["letter", "word"],
3415+
)
3416+
3417+
df3 = pd.DataFrame(
3418+
{"data1": [3, 2, 4, 3, 2, 4, 3, 2], "data2": [6, 5, 7, 5, 4, 5, 6, 5]},
3419+
index=ix3,
3420+
)
3421+
3422+
# Group by index labels and take the means and standard deviations
3423+
# for each group
3424+
gp3 = df3.groupby(level=("letter", "word"))
3425+
means = gp3.mean()
3426+
errors = gp3.std()
3427+
3428+
# No assertion we just ensure that we can plot a MultiIndex bar plot
3429+
means.plot.bar(yerr=errors, capsize=4)
3430+
34043431

34053432
def _generate_4_axes_via_gridspec():
34063433
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)