Violin Plots
What is a violin plot?
A violin plot combines:
- A KDE distribution shape
- A box-plot-like summary inside
It’s useful when you want to see the shape of distributions (multi-modal, skew).
flowchart LR A["Numeric column
per category"] --> B["Compute KDE
for each category"] B --> C["Mirror the KDE curve
left and right"] C --> D["Overlay a mini box
plot in the middle"]
Violin plot in Seaborn
Violin plot
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.violinplot(data=tips, x="day", y="total_bill")
plt.title("Total bill distribution by day")
plt.tight_layout()
plt.show()Violin plot
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.violinplot(data=tips, x="day", y="total_bill")
plt.title("Total bill distribution by day")
plt.tight_layout()
plt.show()Add inner summary
Violin with inner quartiles
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.violinplot(data=tips, x="day", y="total_bill", inner="quartile")
plt.title("Violin plot with quartiles")
plt.tight_layout()
plt.show()Violin with inner quartiles
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
plt.figure(figsize=(7, 4))
sns.violinplot(data=tips, x="day", y="total_bill", inner="quartile")
plt.title("Violin plot with quartiles")
plt.tight_layout()
plt.show()Visualize it
The width of the violin at any height shows how common values near that height are — wider means more data points cluster there:
When to prefer violin vs box
- Use box plots for quick comparisons and outlier focus.
- Use violin plots when the distribution shape matters.
Next
Continue to Bar Plots in Seaborn to compare an aggregated value (like a mean) across categories, with confidence intervals.
🧪 Try It Yourself
Exercise 1 – A Basic Violin Plot
Exercise 2 – Show Quartiles Inside
Exercise 3 – Box vs Violin
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
