Home > Net >  How can I create for each category a horizontal bar plot that consists of shares
How can I create for each category a horizontal bar plot that consists of shares

Time:12-03

I have the following df

    type    eur_d   asia_d  amer_d
0   cat1    0.58    0.30    0.12
1   cat2    0.50    0.29    0.21
2   cat3    0.50    0.30    0.20
3   cat4    0.42    0.31    0.27
4   cat5    0.42    0.37    0.20
5   cat6    0.60    0.21    0.19
6   cat7    0.26    0.50    0.24
7   cat8    0.54    0.17    0.30
8   cat9    0.46    0.25    0.29

Ideally I want to create 9 horizontal bar of same length that shows the share of Europe, Asia, and America for each category with different colors.

CodePudding user response:

If you mean stacked horizontal bar chart, this can help.

df.plot.barh(x="type", stacked=True, figsize=(10, 5))
plt.show()

enter image description here

  • Related