Reputation: 475
I am attempting to use Seaborn's catplot functionality to plot barplots, faceted by two features.
sns.catplot(kind='bar', data=df, col='col1', y='col2', x='col3')
I now want to add the original data (in the form of a stripplot) on top. If I were doing this with only one panel, I would just plot them on the same axes:
fig, ax = plt.subplots()
sns.barplot(data=df, y='col2', x='col3', ax=ax, alpha=0.5)
sns.stripplot(data=df, y='col2', x='col3', ax=ax, dodge=True)
However, since catplot returns a FacetGrid, I cannot figure out how to do the analogous thing. Thanks!
Upvotes: 0
Views: 447
Reputation: 40747
catplot
is a helper function designed to facilitate common faceted plots. If you want more control, you are advised to use FacetGrid
directly:
N = 1000
df = pd.DataFrame({'col1':np.random.choice(['A','B','C'], size=N),
'col2':np.random.random(size=N),
'col3':np.random.choice(['D','E'], size=N)})
g = sns.FacetGrid(data=df, col='col1', col_wrap=2)
g.map_dataframe(sns.barplot, x='col3', y='col2', alpha=0.5, ci=None)
g.map_dataframe(sns.stripplot, x='col3', y='col2')
Upvotes: 2