Skip to content

Commit

Permalink
TST: Add test for plotting MultiIndex bar plot
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nrebena committed Oct 3, 2019
1 parent f122ad8 commit 66dff6b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,33 @@ def test_bar_numeric(self):
ticklocs = ax.xaxis.get_ticklocs()
tm.assert_numpy_array_equal(ticklocs, index)

def test_bar_multiindex(self):
# Test from pandas/doc/source/user_guide/visualization.rst
# at section Plotting With Error Bars
# Related to issue GH: 26186

ix3 = pd.MultiIndex.from_arrays(
[
["a", "a", "a", "a", "b", "b", "b", "b"],
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
],
names=["letter", "word"],
)

df3 = pd.DataFrame(
{"data1": [3, 2, 4, 3, 2, 4, 3, 2], "data2": [6, 5, 7, 5, 4, 5, 6, 5]},
index=ix3,
)

# Group by index labels and take the means and standard deviations
# for each group
gp3 = df3.groupby(level=("letter", "word"))
means = gp3.mean()
errors = gp3.std()

# No assertion we just ensure that we can plot a MultiIndex bar plot
means.plot.bar(yerr=errors, capsize=4)


def _generate_4_axes_via_gridspec():
import matplotlib.pyplot as plt
Expand Down

0 comments on commit 66dff6b

Please sign in to comment.