我希望将这两个箱线图合并成一张图片: [![这是两个数据文件,我能够轻松使用 Seaborn boxplot 制作箱线图][1]][1]
我使用的数据文件来自多个 Excel 电子表格,如下所示:
0 | 1 | 2 | 3 | 4 | 5 | 6 | ... |
---|---|---|---|---|---|---|---|
5 | 2 | 3 | 5 | 6 | 2 | 5 | ... |
2 | 3 | 4 | 6 | 1 | 2 | 1 | ... |
1 | 2 | 4 | 6 | 7 | 8 | 9 | ... |
... | ... | ... | ... | ... | ... | ... | ... |
列标题代表小时,列值是我想用来创建箱线图的那些。
目前我的代码是这样的:
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
xls = pd.ExcelFile('ControlDayVar.xlsx')
df1= pd.read_excel(xls, 'DE_ControlDays').assign(Location=1)
df2= pd.read_excel(xls, 'DE_FestDays').assign(Location=2)
DE_all =pd.concat([df1,df2])
DE= pd.melt(DE_all, id_vars=['Location'], var_name=['Hours'], value_name='Concentration')
ax= sns.boxplot(x='Hours', y= 'Concentration', hue= 'Location', data=DE)
plt.show()
The result I get is this:
[![Yikes][2]][2]
I expect my issue has to do with the format of my data files, but any help would be appreciated.Thanks!
[1]: https://i.stack.imgur.com/dXo6F.jpg
[2]: https://i.stack.imgur.com/NEpi7.jpg
答案 0 :(得分:1)
如果以某种方式 Concentration
值不再被正确识别为数字数据类型,则可能会发生这种情况。
在这种情况下,y 轴不能再被理解为连续的,这可能会导致“yikes”结果。