🎻 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.
Basic 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,yCategory on X-axis, numeric on Y-axis.hueSplit violins by category.
sns.violinplot(data=df, x='day', y='total_bill', hue='sex')
plt.show()
splitShow 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()
paletteChange 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()
cutExtent of violin beyond data range.
sns.violinplot(data=df, x='day', y='total_bill', cut=0)
plt.show()
innerWhat to show inside violin:'box'(default)'quartile''point''stick'None
sns.violinplot(data=df, x='day', y='total_bill', inner='quartile')
plt.show()
linewidthOutline thickness.
sns.violinplot(data=df, x='day', y='total_bill', linewidth=2)
plt.show()
scaleHow 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
penguinsdataset. - Plot
speciesvsbody_mass_g. - Add
hue='sex'. - Set
split=True. - Change
inner='stick'.