简体   繁体   中英

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.

While the relplot having the option to plot scatter and line , the displot have the option to plot hist , kde , ecdf .

Currently, I have to rely on the following code to plot grid of rows and columns that correspond to levels of variable

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. 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?

Apparently, the trick is to use catplot

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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