Aimee Vis
Aimee Vis

Reputation: 51

Stacked bar chart from one column pandas or dictionary

I have been trying to create a stacked bar chart from simple data.

Assume the dictionary:

data ={A:2,B:3, C:4, D:5}

I would like to create a bar chart that shows like this:

example

I cant do it manually (i.e. dividing A by the total and so on) since I have a dictionary that consists of 20 keys.

I feel like it should be so simple but I can't figure it out

Thanks

Upvotes: 1

Views: 130

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150725

You can try:

pd.Series(data).to_frame().T.plot.bar(stacked=True)

Output:

enter image description here

Upvotes: 1

Related Questions