I am having difficulties super-imposing (overlaying) two factorplots using the library seaborn.
The general problem is that I would like to plot in thin grey lines all the (background data) and then on top in colorful, thicker, lines the data we want to highlight. For one I don't succeed combining the two data-sets in a plot with FacetGrid
and secondly I have a problem using zorder
.
I did a dummy example with the exercise
data set:
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'})
Thus far I tried:
factorplot
+factorplot
Plotting two factorplot
s as if it were sns.pointplot
twice analogue to this example. I need to the sns.factorplot
due to the experimental setup of the data. This does not work, as simply two independant plots are produced. I basically would want the lower plot on top of the upper plot.
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)
I thus tried to use sns.factorplot
, which I think produces a FacetGrid
and g.map
a second sns.factorplot
on top using a new dataset with the exact same design and categories. The result is, that instead of using the same subplots, it creates a number of rows with a repeated plot.
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
a pointplot, which puts the entire data set in all the subplots, not respecting the design of the 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')