在Seaborn relplot和displot中,有一个名为col_wrap设置,它支持在对应于变量级别的行和列的网格中排列多个轴。
relplot可以选择plot scatter和line,而displot可以选择绘制hist、kde和ecdf。
目前,我必须依靠以下代码来绘制对应于变量级别的行和列的网格
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()我已经在网上搜索过类似于relplot和displot的东西来绘制boxplot,但是没有用。如果存在这样的方法,如果有人能帮我找到合适的材料,我将不胜感激。
另外,有没有比使用上面提出的代码更紧凑和合适的方法,因为在实际实践中,variables将超过两个?
发布于 2021-03-06 00:54:29
显然,诀窍在于使用catplot
sns.catplot(data=tips, x="sex", y="total_bill", hue="day", col="time", kind="box",col_wrap=1)https://stackoverflow.com/questions/66496022
复制相似问题