简体   繁体   English

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

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

In Seaborn relplot and displot , there are setting called col_wrap that enable multiple axes arrayed in a grid of rows and columns that correspond to levels of variable.在 Seaborn relplotdisplot中,有一个名为col_wrap的设置,可以启用多个轴排列在对应于变量级别的行和列的网格中。

While the relplot having the option to plot scatter and line , the displot have the option to plot hist , kde , ecdf .虽然relplot可以选择plot scatterline ,但displot可以选择 plot histkdeecdf

Currently, I have to rely on the following code to plot grid of rows and columns that correspond to levels of variable目前,我必须依赖以下代码来 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()

I have search the net for something similar to relplot and displot for plotting boxplot , but to no avail.我已经在网上搜索类似于relplotdisplot的东西来绘制boxplot ,但无济于事。 Should such approach exist, really appreciate if someone can direct me to the appropriate material.如果存在这种方法,如果有人可以指导我找到适当的材料,我将不胜感激。

Also, is there more compact and proper way than using the above proposed code since in actual practice, the variables will be more than two?此外,是否有比使用上述建议的代码更紧凑和更合适的方法,因为在实际实践中, variables将超过两个?

Apparently, the trick is to use catplot显然,诀窍是使用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