catplot
creates its own new figure. You can either use catplot
on a "long form dataframe" (using pd.melt()
), or create individual sns.violinplot
s on each ax
.
Using subplots with violinplot
:
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
fig, axes = plt.subplots(1, 2)
sns.violinplot(x='species', y='sepal_length', data=df, ax=axes[0])
sns.violinplot(x='species', y='sepal_width', data=df, ax=axes[1])
plt.tight_layout()
plt.show()
Using catplot
with long form dataframe:
import seaborn as sns
import matplotlib.pyplot as plt
df = sns.load_dataset('iris')
df_long = df.melt(id_vars='species', value_vars=['sepal_length', 'sepal_width'])
sns.catplot(x='species', y='value', col='variable', data=df_long, kind='violin')
plt.tight_layout()
plt.show()
