Violin Plots
What is a violin plot?
Section titled “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
Section titled “Violin plot in Seaborn”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
Section titled “Add inner summary”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
Section titled “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
Section titled “When to prefer violin vs box”- Use box plots for quick comparisons and outlier focus.
- Use violin plots when the distribution shape matters.
Continue to Bar Plots in Seaborn to compare an aggregated value (like a mean) across categories, with confidence intervals.
🧪 Try It Yourself
Section titled “🧪 Try It Yourself”Exercise 1 – A Basic Violin Plot
Section titled “Exercise 1 – A Basic Violin Plot”Exercise 2 – Show Quartiles Inside
Section titled “Exercise 2 – Show Quartiles Inside”Exercise 3 – Box vs Violin
Section titled “Exercise 3 – Box vs Violin”pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading