在boxplot python中添加yes或no元素
这就是我的数据框的外观:在boxplot python中添加yes或no元素,python,boxplot,Python,Boxplot,这就是我的数据框的外观: UnZThick Yield GWQual HazRS Contam 0 0 1 2 4 0 1 0 6 3 4 0 2 0 3 3 4 0 3 0 5 3 4 0 4 0
UnZThick Yield GWQual HazRS Contam
0 0 1 2 4 0
1 0 6 3 4 0
2 0 3 3 4 0
3 0 5 3 4 0
4 0 5 5 4 0
119 9 3 5 6 1
120 9 3 5 7 0
121 9 4 5 7 1
我想创建一个具有厚度与产量的箱线图,每个厚度级别有两个单独的箱线图,这取决于它是否受到污染(0=否,1=是)
到目前为止,我已经:
#Boxplot of unsat thickness vs Yeild
df.boxplot(by= 'UnZThick', column = ['Yield'])
plt.xlabel('Unsaturated Thickness')
plt.ylabel('Yield')
plt.savefig('Plot3 as PNG.png', format='png',
dpi=600],)
seaborn图书馆使这一点非常直截了当。当应用于整个df时,箱线图将更有意义
import pandas as pd
import numpy as np
import seaborn as sns
df = pd.DataFrame({'UnZThick': [0, 0, 0, 0, 0, 9, 9, 9],
'Yield': [1, 6, 3, 5, 5, 3, 3, 4],
'GWQual': [2, 3, 3, 3, 5, 5, 5, 5],
'HazRS': [4, 4, 4, 4, 4, 6, 7, 7],
'Contam': [0, 0, 0, 0, 0, 1, 0, 1]})
# If you want to make the Contam values yes/no
df['Contam'] = np.where(df['Contam']==1,'Yes','No')
# Use hue to split by Contam field
g = sns.boxplot(data=df, hue='Contam', y='Yield', x='UnZThick')
g.get_figure().savefig('img.png')
请发布实际数据,而不是它的图片。结尾的方括号
dpi=600]
对我来说似乎是错误的。对不起。。我想要dataframe中0-121之间的所有值