Violin plots are a powerful and elegant way to visualize the distribution of a continuous variable across different categories. By combining the features of box plots and kernel density estimates, violin plots reveal not just summary statistics, but also the full distribution shape and variability of the data in a single, compact graphic.
Today, I want to explore with you how to create violin plots using Seaborn, a Python visualization library built on top of Matplotlib.
Seaborn makes it easy to generate attractive, informative statistical graphics with just a few lines of code, perfect for quickly gaining insights from your data.
Whether you’re new to violin plots (or plots in general!) or just need a refresher, this guide will walk you through their key features, advantages, and use cases to help you decide when and how to use them effectively.
Let’s dive in!
What is a Violin Plot?
A violin plot is a versatile chart that displays summary statistics such as the median, quartiles, and range. As opposed to box plots, it goes a step further by including an illustration of the density of the data across different values, offering deeper insights into its distribution.

Image by Author
It combines the structure of a box plot with a mirrored kernel density plot. This dual representation highlights the central tendency and variability and reveals the probability density too, showing how data is distributed at various levels. The unique shape of a violin plot can capture nuances such as multiple modes in the data, which a box plot may overlook.
This makes violin plots particularly valuable when you need a more detailed view of the data’s variability and distribution, including patterns like clustering or multimodality. They are ideal for comparing distributions across categories while providing a comprehensive visual summary.
Creating our Violin Plot with Python and Seaborn
Before creating any chart, we first need to have Seaborn installed in our environment. We can use the pip packager manager and execute the following command:
pip install seaborn
Once installed, we’re ready to dive in. For this example, we’ll use Seaborn’s built-in exercises dataset, a classic dataset that records information about the pulse of different subjects depending on the kind of exercise (rest, running, and walking) and their diet (low-fat and fat).
First, we will import the Seaborn library and load the “exercises” dataset:
import seaborn as sns
exercise = sns.load_dataset("exercise")
If you want to check the seaborn default libraries, you can easily do so by executing the following command.
sns.get_dataset_names()
You will see there are over 20 datasets that can be used. Next, we can easily create a violin chart that shows the distribution of the pulse by the kind of exercise. To do so, we can use the violinplot() function from Seaborn to create the chart.
sns.violinplot(x="kind", y="pulse", data=exercise)
In the previous code, we have:
- x (categorical column): Specifies the categorical variable to be plotted along the x-axis. Each unique category will have its own violin. In our case, we have three main kinds.
- y (numeric column): Specifies the continuous numerical variable to be plotted along the y-axis. The shape of each violin reflects the distribution of this variable within each category.
- your dataframe: The DataFrame containing the data you want to visualize.

Image by Author
By default, Seaborn creates one violin per category in the x-axis. For example, if you’re plotting pulse by type of exercise using the exercise dataset, and there are three unique days (“Rest”, “Walking”, “Running”), the plot will display three violins.
How to Interpret a Violin Plot
A violin plot displays both the distribution and summary statistics of the data:
- The violin shape shows the density of the data at different values
- The white dot in the center represents the median
- The thick black bar indicates the interquartile range (IQR), the middle 50% of the data
- The thin black lines (or “whiskers”) show the full range of the data
Further Customization
Here is how to further customize your violin plot in some additional ways.
Palette of Colors
Seaborn’s violinplot() function offers several parameters to help you tailor the look and feel of your plots. One of the most commonly used options is the palette parameter, which controls the color scheme used for the violins.
sns.violinplot(x="kind", y="pulse", data=exercise, palette="Set3")
In this example, we apply the “Set3” color palette, which provides a set of visually distinct colors ideal for categorical data. This makes it easier to distinguish between different exercise types in the plot.
Segmentation by an Additional Variable
You can also enhance the plot by introducing a second categorical variable using the hue parameter. This splits each violin into subcategories, allowing for deeper comparisons.
sns.violinplot(x="kind", y="pulse", data=exercise, palette="Set3", hue="diet")
The hue parameter specifies the variable that we want to use to split the violins. In this case, we want to split the violins by the gender of the person who paid the bill. Seaborn creates a separate violin for each combination of day of the week and gender.
Adding Individual Data Points
We can also add a swarm plot to the violin chart to show the individual data points.
sns.violinplot(x="kind", y="pulse", data=exercise, palette="Set3") sns.swarmplot(x="kind", y="pulse", data=exercise, color="black", size=3)

Image by Author
Splitting Violin Plots
The split parameter in the violinplot() function splits the violins for each combination of categories in the x and hue variables.
sns.violinplot(x="kind", y="pulse", data=exercise, palette="Set3", hue="diet", split=True)
Polishing Your Violin Plot
Creating a good violin plot is just the beginning. Making it clear, readable, and visually compelling is what turns it into a great one. To make your chart presentation ready, it’s important to include:
- A descriptive title that explains what the viewer is looking at
- Axis labels that clarify the variables
- A consistent and readable style (grid, spacing, color palettes)
- And of course, a layout that doesn’t feel cramped
Here’s how we can bring it all together in a clean and professional way:
import seaborn as sns
import matplotlib.pyplot as plt
# Load the dataset
exercise = sns.load_dataset("exercise")
# Set the figure size and style
plt.figure(figsize=(10, 6))
sns.set(style="whitegrid")
# Create the violin plot with overlayed swarm plot
sns.violinplot(x="kind", y="pulse", data=exercise, palette="Set3", inner=None)
sns.swarmplot(x="kind", y="pulse", data=exercise, color="black", size=3)
# Add title and labels
plt.title("Pulse Distribution by Type of Exercise", fontsize=16)
plt.xlabel("Type of Exercise", fontsize=12)
plt.ylabel("Pulse Rate", fontsize=12)
# Improve layout
plt.tight_layout()
plt.show()

Image by Author
Alternative Functions
While violinplot() is the go-to function for creating violin charts, Seaborn also offers other powerful tools for visualizing distributions:
Using Catplot
catplot() is a versatile, high-level function for creating different types of categorical plots—including violin plots. It allows you to combine multiple plot types with additional facets (e.g., columns or rows) for grouped visualizations.
sns.catplot(x="kind", y="pulse", data=exercise, kind="violin")
Using Boxenplot
boxenplot() is a variation of the box plot that is especially effective for visualizing large datasets with long tails. Unlike violin plots, it uses nested boxes to display the distribution and density, providing more detail in the extremes of the data.
sns.boxenplot(x="kind", y="pulse", data=exercise)
Conclusions
Seaborn is a powerful and user-friendly Python library for creating rich, informative visualizations, including violin plots. Violin charts are especially useful for exploring the distribution of continuous variables across multiple categories, as they reveal both summary statistics and the full shape of the data.
With Seaborn’s intuitive functions and customizable parameters, you can create visually appealing violin plots that not only look great but also deliver valuable insights into your data with minimal effort.
You can find the code in my articles repository.
