繁体   English   中英

类似于 relplot 和 displot 的东西,用于使用 Seaborn 绘制箱线图

[英]Something similar to relplot and displot for plotting boxplot with Seaborn

在 Seaborn relplotdisplot中,有一个名为col_wrap的设置,可以启用多个轴排列在对应于变量级别的行和列的网格中。

虽然relplot可以选择plot scatterline ,但displot可以选择 plot histkdeecdf

目前,我必须依赖以下代码来 plot 网格对应于变量级别的行和列

import matplotlib.pyplot as plt

import seaborn as sns
sns.set(style="ticks")
tips = sns.load_dataset("tips")
plt.figure(figsize=(15,10))
variables=['Lunch','Dinner']
for i, c in enumerate(variables, 1):
    filter_ch = tips ["time"].isin ( [c] )
    dv = tips [filter_ch].reset_index ( drop=True )
    plt.subplot(2,1,i)
    g = sns.boxplot(x='sex', y="total_bill",hue='day',data=dv)


plt.show()

我已经在网上搜索类似于relplotdisplot的东西来绘制boxplot ,但无济于事。 如果存在这种方法,如果有人可以指导我找到适当的材料,我将不胜感激。

此外,是否有比使用上述建议的代码更紧凑和更合适的方法,因为在实际实践中, variables将超过两个?

显然,诀窍是使用catplot

sns.catplot(data=tips, x="sex", y="total_bill", hue="day", col="time", kind="box",col_wrap=1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM