【发布时间】:2018-04-28 17:34:02
【问题描述】:
我在使用 seaborn 库对两个 factorplots 进行叠加(叠加)时遇到了困难。
一般的问题是,我想用灰色细线绘制所有(背景数据),然后在顶部用彩色、粗线绘制我们想要突出显示的数据。一方面,我没有成功地将两个数据集与FacetGrid 组合在一个绘图中,其次我在使用zorder 时遇到了问题。
我用exercise 数据集做了一个虚拟示例:
sns.set_style('whitegrid')
exercise = sns.load_dataset("exercise")
background = exercise.assign(idkind = lambda df: df['id'].astype(str)+df.kind.astype(str))
foreground = exercise.groupby(['kind','time']).mean().reset_index().rename(columns={'id':'idkind'})
到目前为止我尝试过:
factorplot+factorplot
绘制两个factorplots,就好像它是sns.pointplot 两次模拟this example。由于数据的实验设置,我需要sns.factorplot。这不起作用,因为只生成了两个独立的图。我基本上希望下图在上图之上。
g=sns.factorplot(x="time", y="pulse", hue='idkind', col='kind', legend=False,color='lightgrey',data=background)
sns.factorplot(x="time", y="pulse", hue="kind", data=foreground)
factorplot+gmap.(factorplot)
因此,我尝试使用sns.factorplot,我认为它会在顶部使用具有完全相同设计和类别的新数据集生成FacetGrid 和g.map 第二个sns.factorplot。结果是,它没有使用相同的子图,而是创建了许多具有重复图的行。
g=sns.factorplot(x="time", y="pulse", hue='idkind', col='kind', legend=False,color='lightgrey',data=background)
g.map(sns.factorplot, x="time", y="pulse",hue='idkind', col='kind', data=foreground)
factorplot+g.map(pointplot)
g.map一个点图,将整个数据集放在所有子图中,不尊重FacetGrid的设计。
g=sns.factorplot(x="time", y="pulse", hue='idkind', col='kind', legend=False,color='lightgrey',data=background)
g.map(sns.pointplot,x="time", y="pulse", hue='idkind', col='kind', data=foreground,zorder='1000')
【问题讨论】:
标签: python matplotlib plot seaborn facet-grid