In this tutorial, we will learn how to make group violinplots with Seaborn in Python. In Seaborn, we have atleast two ways to make violinplots using Seaborn in Pyhon. First is to use violinplot() function and make violinplot. And the second option is to use Seaborn’s catplot() function. In this post, we will start with making a simple violinplot first and use both violinplot() function and catplot() function to learn to make grouped violinplot.
Let us load the libraries needed.
import matplotlib.pyplot as plt import pandas as pd import seaborn as sns
penguins_data="https://raw.githubusercontent.com/datavizpyr/data/master/palmer_penguin_species.tsv"
penguins_df = pd.read_csv(penguins_data, sep="\t") penguins_df.head()
plt.figure(figsize=(8,6)) sns.violinplot(y="flipper_length_mm", x="species", data=penguins_df) plt.savefig("violinplot_Seaborn_Python.png", format='png', dpi=150)
Grouped Violinplot with Seaborn violinplot()
plt.figure(figsize=(8,6)) sns.violinplot(y="flipper_length_mm", x="species", #hue="species", hue="sex", data=penguins_df) plt.savefig("grouped_violinplot_with_Seaborn_violinplot.png", format='png',dpi=150)
Grouped Violinplot with Seaborn Catplot
sns.catplot(y="flipper_length_mm", x="species", hue="sex", kind="violin", data=penguins_df, height=8) plt.savefig("grouped_violinplot_with_Seaborn_catplot.png", format='png', dpi=150)