How to plot a side-by-side grouped bar plot

Viewed 55
import pandas as pd
income_analysis = pd.DataFrame({'Household Income': ['0-24,999', '25,000-49,999', '50,000'], 'rank1': [3,2,1], 'rank2': [1,2,3]})

  Household Income  rank1  rank2
0         0-24,999      3      1
1    25,000-49,999      2      2
2           50,000      1      3

sns.barplot(data = income_analysis, x = 'Household Income', y = 'rank1')

enter image description here

I am trying to make a bar chart where each set of bars is a different rank, and within each set of bars it is divided based on household income. So all together, 6 bar, 2 sets of bars, 3 bars in each set. My marplot above plots one of them, but how do I do it for both?

1 Answers

Try this,transpose and pandas plot:

income_analysis.set_index('Household Income', inplace=True)

income_analysis.T.plot.bar()
plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left')

enter image description here

Related