0

I have a dataset (see example below), which I would like to plot as a stacked bar plot.

I want each bar consists of 3 values,each group of bar plots to consist of 6 bars, and for there to be 3 such groups. For example

Year Country Cars Motorbikes Bikes
2010 UK 3 2 5
2010 France 1 1 5
2010 Germany 1 2 5
2010 USA 4 2 5
2010 Italy 5 6 5
2010 Spain 6 7 5
2015 UK 1 2 8
2015 France 5 3 5
2015 Germany 4 2 9
2015 USA 3 2 6
2015 Italy 2 2 5
2015 Spain 4 6 4
2020 UK 1 2 3
2020 France 2 1 1
2020 Germany 1 2 3
2020 USA 1 2 8
2020 Italy 3 4 1
2020 Spain 2 3 2

So in this example, there would be a group of bar plots for 2010, one for 2015 and one for 2020. Each group would have one bar for each country. And each bar would consist of cars, motorbikes and bikes, with the top of the bar reaching the sum of the 3 values.

I can produce a stacked bar plot if I use pandas plotting, but I can't figure out how to group these. Alternatively, I can use 'hue' in seaborn to group them, but as far as I'm aware, seaborn doesn't support stacked bar plots.

Is there any way I can combine both of these features?

Edit: I don't particularly need different colour palettes for each yeah. I guess I mostly just want them spaced out differently. i.e. a larger space at the end of one group than between elements within a group.

user112495
  • 184
  • 9
  • Does this answer your question? [How to create a stacked bar chart for my DataFrame using seaborn?](https://stackoverflow.com/questions/47138271/how-to-create-a-stacked-bar-chart-for-my-dataframe-using-seaborn) – mpx Mar 08 '21 at 14:27
  • @balandongiv I don't think so, as that doesn't seem to be grouped along the x-axis. That's just for getting stacked bar plots. But their answer involves the pandas plotting method, and so doesn't accept 'hue' as a keyword I don't think. – user112495 Mar 08 '21 at 14:29

0 Answers0