Horizontal violin plot with Seaborn

logo of a chart:Violin

A violin plot is a graphical representation employed to depict the distribution of a dataset, showcasing important statistics like the median, quartiles, and possible outliers. It offers a succinct summary of the central tendency and dispersion of the data.

Creating violin plots with Seaborn allows us to easily visualize the distribution. In this post, we will explore how to use Seaborn to create a horizontal violin plot.

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:

  
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.

  
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.

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    dataviz decision tree poster