gpt4 book ai didi

pandas - 猫图的 Seaborn FacetGrid

转载 作者:行者123 更新时间:2023-12-04 02:43:20 26 4
gpt4 key购买 nike

我一直在与 seaborn.catplot 一起工作为了有一个条形图(下面的数据样本)将 counts 中的值相加一套的列reasons ,由一组公司分隔:

sns.catplot(x='Bill_Name', y='counts', hue='Reason', 
data=data, kind='bar', height=6, aspect=13/6,
legend=True, palette='hls')

enter image description here

现在对于每个值还有一列 year .所以我在考虑使用 seaborn.FacetGrid , 以便在行网格中显示上述内容。

因此,如果我理解其正常工作的方式, sns.FacetGrid必须提供数据和 year在这种情况下,列为 row参数,然后使用 sns.map , 与 sns.catplot及其相应的参数,但是这不能正常工作:
g = sns.FacetGrid(data, row="year", height=4, aspect=.5)
g = g.map(sns.catplot, x='Bill_Name', y='counts', hue='Reason',
data=data, kind='bar', height=6, aspect=13/6,
legend=True, palette='hls')

我究竟做错了什么?

以下是数据示例:
   Bill_Name      year   Reason  counts
0 CompanyC 2018.0 Reason6 2
1 CompanyC 2017.0 Reason5 8
2 CompanyB 2017.0 Reason3 146
3 CompanyC 2015.0 Reason6 2
4 CompanyC 2017.0 Reason1 1828
5 CompanyC 2016.0 Reason3 237
6 CompanyB 2018.0 Reason4 1097
7 CompanyC 2016.0 Reason4 11
8 CompanyB 2016.0 Reason5 12
9 CompanyC 2017.0 Reason2 834
10 CompanyB 2016.0 Reason3 97
11 CompanyC 2017.0 Reason6 714
12 CompanyA 2017.0 Reason1 4288
13 CompanyA 2016.0 Reason2 2444
14 CompanyC 2017.0 Reason3 293
15 CompanyB 2016.0 Reason1 1576
16 CompanyA 2016.0 Reason4 37
17 CompanyA 2018.0 Reason5 1
18 CompanyC 2018.0 Reason1 908
19 CompanyC 2018.0 Reason2 478
20 CompanyA 2015.0 Reason1 3826
21 CompanyB 2016.0 Reason4 119
22 CompanyB 2017.0 Reason2 1404
23 CompanyC 2016.0 Reason1 1884
24 CompanyC 2015.0 Reason4 1
25 CompanyA 2016.0 Reason1 6360
26 CompanyA 2018.0 Reason3 225
27 CompanyA 2018.0 Reason4 63
28 CompanyC 2018.0 Reason4 162
29 CompanyC 2016.0 Reason2 1504

最佳答案

您可以避免 facetgrid完全如果你添加 row='year'对seaborn的争论catplot :

sns.catplot(x='Bill_Name', y='counts', hue='Reason',row='year', data=data, kind='bar', height=6, aspect=13/6, legend=True, palette='hls')

关于pandas - 猫图的 Seaborn FacetGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58267193/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com