Ahamed Moosa
Ahamed Moosa

Reputation: 1445

How to do draw a seaborn or a matlab plot

I have a dataframe which looks like below

            A   B   C
Above 90%   30  50  60
80% - 90%   39  72  79
65% - 80%   80  150 130
Below 65%   80  70  90

And I would like to get a bar chart like below

enter image description here

And I have another dataset which has one more sub category for A, B and C

Company Category    Above 90%   80% - 90%   65% - 80%   Below 65%
A       Fast Movers 1           11          21          9
A       Med Movers  2           13          42          40
A       Slow Movers 34          26          44          50
B       Fast Movers 1           11          21          9
B       Med Movers  16          48          92          45
B       Slow Movers 33          13          37          45
C       Fast Movers 0           0           2           30
C       Medi Movers 11          37          74          50
C       Slow Movers 41          42          65          30

For the above table I want a stacked bar chart with colors only for categories and I want Company and accuracy to be labels not colors.

I was not even able to achieve it using other softwares.

I request you all to kindly help me to achieve it, I will appreciate your time and help.

Thank you in advance

Upvotes: 0

Views: 895

Answers (2)

jezrael
jezrael

Reputation: 862511

You can use:

df.set_index(['Company','Category']).stack().unstack(1).plot.bar(stacked=True)

pic

Or for each company separate graph:

for i, x in df.set_index(['Company','Category']).stack().unstack(1).reset_index(level=0).groupby('Company'):
    x.plot.bar(stacked=True)

Upvotes: 2

Joe
Joe

Reputation: 12417

For the first question, you can use this:

import matplotlib.pyplot as plt
ax = df.plot(kind='bar', title ="Accuracy distribution", figsize=(15, 10), legend=True, fontsize=12)
for p in ax.patches:
    ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))
plt.show()

Upvotes: 3

Related Questions