🎻 Seaborn Violin Plot
Last Updated: 07 Nov 2025
A violin plot is a combination of box plot + KDE (smooth density curve). It shows:
- Median, Quartiles (like boxplot)
- Shape of distribution (like KDE)
Hinglish Tip 🗣: Box plot se zyada detail chahiye ho — data ka shape bhi dekhna ho — toh violin plot best.
Syntax
sns.violinplot(data=df, x='category', y='numeric')
plt.show()
📘 Example Dataset
df = sns.load_dataset('tips')
df.head()
🎻 Basic Violin Plot
sns.violinplot(data=df, x='day', y='total_bill')
plt.show()
Important Parameters
- data, x, y Category on X-axis, numeric on Y-axis.
- hue Split violins by category.
sns.violinplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
- split Show two distributions in one violin (works with hue having 2 categories).
sns.violinplot(data=df, x='day', y='total_bill', hue='sex', split=True)
plt.show()
- palette Change colors.
sns.violinplot(data=df, x='day', y='total_bill', palette='magma')
plt.show()
- bw (Bandwidth) Controls smoothness of KDE. (Smaller = sharper, Larger = smoother)
sns.violinplot(data=df, x='day', y='total_bill', bw=0.2)
plt.show()
- cut Extent of violin beyond data range.
sns.violinplot(data=df, x='day', y='total_bill', cut=0)
plt.show()
- inner What to show inside violin:
- 'box' (default)
- 'quartile'
- 'point'
- 'stick'
- None
sns.violinplot(data=df, x='day', y='total_bill', inner='quartile')
plt.show()
- linewidth Outline thickness.
sns.violinplot(data=df, x='day', y='total_bill', linewidth=2)
plt.show()
- scale How width of violin is scaled:'area','count','width'
sns.violinplot(data=df, x='day', y='total_bill', scale='width')
plt.show()
⭐ Full Example
sns.violinplot(
data=df,
x='day',
y='total_bill',
hue='sex',
split=True,
palette='viridis',
bw=0.3,
inner='quartile',
linewidth=1.5,
scale='width',
cut=0
)
plt.show()
Quick Practice
- Load penguins dataset.
- Plot species vs body_mass_g.
- Add hue='sex'.
- Set split=True.
- Change inner='stick'.
