Violin Plot

Purpose

Combine box plot and kernel density estimation to show distribution shape, spread, and probability density at different values.

Analysis Type

Univariate or Bivariate (across categories)

What to Look For

1. Distribution Shape
2. Modality
3. Symmetry
4. Comparing Groups
5. Central Tendency
6. Tail Behavior
7. Linearity

Code Example

# Basic violin plot
sns.violinplot(y='value', data=df)
plt.title("Violin Plot of Variable")
plt.show()

# Grouped violin plot
sns.violinplot(x='category', y='value', data=df, hue='group')
plt.title("Value Distribution Across Categories and Groups")
plt.show()

# Split violin for comparison
sns.violinplot(x='category', y='value', data=df, hue='binary_group', split=True)
plt.title("Split Violin Plot by Binary Group")
plt.show()
Pro Tip

Use inner='quartile' parameter to show quartile lines inside violins: sns.violinplot(x='cat', y='val', data=df, inner='quartile'). This combines the best of box plots (quartiles) with density visualization. For comparing two groups, use split=True with a binary hue variable to create mirror violins for easy comparison.

ML_AI/_feature_engineering/images/vio-1.png

Documentation