Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何绘制seaborn或matlab绘图_Python_Pandas_Matplotlib_Seaborn - Fatal编程技术网

Python 如何绘制seaborn或matlab绘图

Python 如何绘制seaborn或matlab绘图,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,我有一个数据框,如下所示 A B C Above 90% 30 50 60 80% - 90% 39 72 79 65% - 80% 80 150 130 Below 65% 80 70 90 我想得到下面这样的条形图 A B C Above 90% 30 50 60 80% - 90% 39 72 79 65% - 80% 80 150 130 Below 65% 80

我有一个数据框,如下所示

            A   B   C
Above 90%   30  50  60
80% - 90%   39  72  79
65% - 80%   80  150 130
Below 65%   80  70  90
我想得到下面这样的条形图

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

我还有另一个数据集,它还有一个子类A,B和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
对于上面的表格,我想要一个只有类别颜色的堆叠条形图,我想要公司和精度是标签而不是颜色

我甚至不能用其他软件来实现它

我请求你们帮助我实现这一目标,我将感谢你们的时间和帮助


提前感谢您

对于第一个问题,您可以使用以下内容:

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()

对于第一个问题,您可以使用:

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()
您可以使用:

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

或对于每个
公司
单独的图表:

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

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

或对于每个
公司
单独的图表:

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

请分享你迄今为止尝试的代码,并告诉我们你得到了什么错误。请分享你迄今为止尝试的代码,并告诉我们你得到了什么错误。谢谢Jezrael,我在我的第一张图表中使用了df.set_index(['accurity']).plot.bar(stacked=False,figsize=(10,5))。我是否可以包括数据标签并调整大小it@AhamedMoosa-不容易,我想需要解决注意的伙计,谢谢你的帮助。我真的很欣赏它Hanks Jezrael,我在第一张图表中使用了df.set_index(['accurity']).plot.bar(stacked=False,figsize=(10,5))。我是否可以包括数据标签并调整大小it@AhamedMoosa-不容易,我想需要解决注意的伙计,谢谢你的帮助。我真的很感激我,乔,谢谢你的回答。如果我想水平显示xlabel,而不是vertically@AhamedMoosa不客气。添加这行代码
plt.xticks(rotation='horizontal')
Hi joe,您是否可以使用int而不是float@AhamedMoosa添加
int
如下:
ax.annotate(str(int(p.get\u height()),(p.get\u x()*1.005,p.get\u height()*1.005))
你好,乔,谢谢你的回答。如果我想水平显示xlabel,而不是vertically@AhamedMoosa不客气。添加这行代码
plt.xticks(rotation='horizontal')
Hi joe,您是否可以使用int而不是float@AhamedMoosa添加
int
如下:
ax.annotate(str(int(p.get\u height()),(p.get\u x()*1.005,p.get\u height()*1.005))