I would like to plot a bar chart of categorical data, grouped by series.
E.g. i have data with say 6 columns, here below filled with arbitrary values:
df = pd.DataFrame(np.arange(12).reshape(2,6),columns=['A','B','C','D','E','F'])
A B C D E F
0 0 1 2 3 4 5
1 6 7 8 9 10 11
and I would like to simply plot this simple information as a bar chart where for each of the column names A-F, there will show one bar (with its name on the axis or inline) for row 0
and one bar for row 1
, each bar having it's height being the number in the body of the matrix for that row and column.
Like normal grouped bar charts, all bars for row 0
should be a different color than those for row 1
. Simply put, just a histogram for the categories A-F grouped by the two rows.
Actually in my real data each row has a real name instead of just an index number which is here 0
and 1
for the two rows.
I've found no way so far to get this done with seaborn, and only saw some terrible hacks with matplotlib itself. What is the simplest way to accomplish this?
Is there a way?
You can use plotly to draw grouped bar charts. plotly draw graphs and chart very interactive and attractive. Here is an example.
Import libraries:
Create DataFrame :
Plot Bar Chart:
You may plot the transposed dataframe like
df.T.plot.bar()
.Using seaborn this requires to reshape ("melt") the dataframe: