Python Seaborn Violin绘图未正确显示
我正在使用SeabornPython Seaborn Violin绘图未正确显示,python,matplotlib,seaborn,violin-plot,Python,Matplotlib,Seaborn,Violin Plot,我正在使用Seabornviolinplot()和swarmlot()来显示数据帧中的数据。Swarmlot工作正常,而我在使用violinplot时遇到问题 我在循环中绘制了所有的图,大多数图都如预期的那样显示出来,但有一些图没有相应的小提琴。对于相同的数据部分,在没有循环的情况下也会发生这种情况 带有错误的绘图的数据帧 非常感谢您抽出时间 CDS source 0 3158 nature 1 2879 DTU 2 2881 DTU 3 3103
violinplot()
和swarmlot()
来显示数据帧中的数据。Swarmlot工作正常,而我在使用violinplot
时遇到问题
我在循环中绘制了所有的图,大多数图都如预期的那样显示出来,但有一些图没有相应的小提琴。对于相同的数据部分,在没有循环的情况下也会发生这种情况
带有错误的绘图的数据帧
非常感谢您抽出时间
CDS source
0 3158 nature
1 2879 DTU
2 2881 DTU
3 3103 dairy
4 2992 nature
5 3127 dairy
6 3127 nature
7 2879 dairy
8 3116 nature
9 3091 nature
10 3014 dairy
11 3003 nature
12 2951 dairy
13 3161 nature
14 2960 nature
15 2971 nature
16 3138 nature
17 3153 nature
18 2878 DTU
19 2882 DTU
20 2880 DTU
21 2880 DTU
22 2942 nature
23 3027 dairy
24 3021 dairy
25 3395 nature
26 3160 nature
27 2997 nature
28 3094 nature
29 2798 nature
30 3082 dairy
31 3061 nature
32 2912 nature
33 2952 nature
34 3154 nature
35 3158 nature
36 2980 dairy
37 3069 dairy
38 3080 nature
39 2880 DTU
40 3301 nature
41 3042 nature
42 3154 nature
43 3034 nature
44 2983 dairy
45 2981 nature
46 3049 nature
47 3090 dairy
48 2987 nature
49 2828 nature
50 2924 nature
51 3108 dairy
52 3128 nature
53 3030 nature
54 3120 nature
55 3176 nature
56 3185 nature
57 3205 nature
58 2987 nature
59 2900 nature
60 3247 nature
61 3144 nature
62 3092 nature
63 2944 dairy
64 3284 nature
65 2947 nature
66 3185 dairy
67 2715 dairy
68 2924 nature
69 2929 nature
70 2961 nature
71 3172 nature
72 3161 nature
73 3200 nature
74 2913 nature
75 3157 nature
76 2965 nature
77 2940 nature
78 3104 dairy
79 3015 dairy
80 3022 dairy
81 3119 nature
82 3189 dairy
83 3179 nature
代码:
对于物种列表中的物种:
dfplot=df[df['species'].isin([species])]
ax=sns.violinplot(data=dfplot,x='source',y='CDS',order=[“dairy”,“DTU”,“nature”],inner=None)
ax=sns.swarmlot(数据=dfplot,x='source',y='CDS',顺序=[“dairy”,“DTU”,“nature”],颜色=(“白色”),edgecolor=“黑色”,线宽=0.7)
plt.show()
plt.clf()
误差小提琴图
正确:
很少有数据点的
源==“DTU”
;此外,它们的'CDS'
值非常接近。中央小提琴图的高度几乎为零
具有参数比例
,默认为区域
。要使所有面积相等,其他两个小提琴必须非常窄。设置scale='width'
使所有小提琴的宽度相等:
ax=sns.violinplot(data=dfplot,x='source',y='CDS',order=[“dairy”,“DTU”,“nature”],
内部=无,比例=宽度')
ax=sns.swarmlot(数据=dfplot,x='source',y='CDS',顺序=[“dairy”,“DTU”,“nature”],
颜色=(“白色”),edgecolor=“黑色”,线宽=0.7,ax=ax)
左边的图像是生成的图,右边的图像放大到一个非常有限的y区域,集中在“CTU”小提琴图上
很少有数据点的
源==“DTU”
;此外,它们的'CDS'
值非常接近。中央小提琴图的高度几乎为零
具有参数比例
,默认为区域
。要使所有面积相等,其他两个小提琴必须非常窄。设置scale='width'
使所有小提琴的宽度相等:
ax=sns.violinplot(data=dfplot,x='source',y='CDS',order=[“dairy”,“DTU”,“nature”],
内部=无,比例=宽度')
ax=sns.swarmlot(数据=dfplot,x='source',y='CDS',顺序=[“dairy”,“DTU”,“nature”],
颜色=(“白色”),edgecolor=“黑色”,线宽=0.7,ax=ax)
左边的图像是生成的图,右边的图像放大到一个非常有限的y区域,集中在“CTU”小提琴图上
物种列表
未定义物种列表
未定义非常感谢!我不知道参数scale
有默认的area
。这解决了我的问题。我知道为什么带有source==“DTU”
的数据点显示为这样,这是正确的。非常感谢!我不知道参数scale
有默认的area
。这解决了我的问题。我知道为什么带有source==“DTU”
的数据点显示为这样,这是正确的。