如果我理解正确,您可能希望从融合您的数据框开始,因为它目前是宽格式和 Seaborn prefers long or tidy format。
然后你可以使用sns.catplot() 这样你就有了三个地块,而不是一个。来自docs:
使用 catplot() 组合 boxplot() 和 FacetGrid。这允许
在其他分类变量中分组。使用 catplot() 是
比直接使用 FacetGrid 更安全,因为它可以确保同步
跨方面的可变顺序:
### Make dummy dataframe
id = np.arange(1,10,1)
np.random.seed(0)
CCL = list(np.random.randint(5, size=len(id)))
CMCT = list(np.random.randint(8, size=len(id)))
CD = list(np.random.randint(5, size=len(id)))
CPAA = list(np.random.randint(9, size=len(id)))
CSC = list(np.random.randint(12, size=len(id)))
SIE = list(np.random.randint(5, size=len(id)))
CEC = list(np.random.randint(7, size=len(id)))
labels = list(np.random.randint(3, size=len(id)))
df = pd.DataFrame(list(zip(id, CCL, CMCT, CD, CPAA, CSC, SIE, CEC, labels)),
columns =['id', 'CCL', 'CMCT', 'CD', 'CPAA', 'CSC', 'SIE', 'CEC', 'labels']
)
print(df)
### Now melt and plot
df_melt = pd.melt(df, id_vars=['id', 'labels'],
value_vars=['CCL', 'CMCT', 'CD', 'CPAA', 'CSC', 'SIE', 'CEC']
)
print(df_melt)
sns.catplot(data=df_melt, x='value', y='variable', col='labels', kind='box')
plt.show()