'Plot multiple columns side by side
I have the dataframe below.
111_a 111_b 222_a 222_b 333_a 333_b
row_1 1.0 2.0 1.5 2.5 1.0 2.5
row_2 1.0 2.0 1.5 2.5 1.0 2.5
row_3 1.0 2.0 1.5 2.5 1.0 2.5
I'm trying to plot a bar chart such that column *_a
are together, and *_b
are together. I would also be plotting each row (row_1
, row_2
, etc) in separate tables.
What I'm trying to get is this:
where in my case,
Asia.SUV = 111_a, Europe.SUV = 222_a, USA.SUV = 333_a
Asia.Sedan = 111_b, Europe.Sedan = 222_b, USA.Sedan = 333_b
I would rename the "Type". How can I plot this? It would also be a bonus if I can plot each row in separate tables with just a command, instead of manually plotting each row.
Solution 1:[1]
Assuming df
the dataframe, you can use:
ax = df.T.rename_axis(columns='Origin', index='Type').plot.bar()
ax.set_ylabel('Frequency')
output:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | mozway |