Libraries

First, you need to install the following librairies:

import seaborn as sns
import matplotlib.pyplot as plt

Dataset

The dataset we will use is the iris dataset, which we can easily download with seaborn:

df = sns.load_dataset('iris')

Violin plot

Fortunately, it's a very light syntax to create a violin plot with seaborn thanks to the violinplot() function:

Horizontal violin plot with Seaborn: Violin plot

  
sns.set_theme(style="darkgrid")
 
# Just switch x and y
sns.violinplot(x=df["species"], y=df["sepal_length"])
plt.show()

Flipped violin plot

Flipping this graph is actually quite simple, as all you have to do is exchange the arguments x and y.

Horizontal violin plot with Seaborn: Flipped violin plot

  
sns.set_theme(style="darkgrid")
 
# Just switch x and y
sns.violinplot(y=df["species"], x=df["sepal_length"])
plt.show()

Going further

This post explains how to create a horizontal violin plot with seaborn.

For more examples of how to create or customize your violin plots, check the violin plot section. You may also be interested in how to customize a violin plot.