What is a Violin Plot?
A violin plot combines a box plot with a kernel density estimation (KDE) mirrored on each side, showing the full distribution shape — not just summary statistics. The width of the violin at any point represents the relative density of data values, revealing patterns a box plot alone cannot show.
The plot was introduced by Hintze and Nelson in 1998 as a merger of two classics: Tukey's box plot (which shows the five-number summary) and the density trace (which shows where data concentrates). Inside each violin you still see the median, quartiles, and whisker range — but around them, the smoothed density curve shows how the data fills that range.
This matters because summary statistics can be identical for very different distributions. Two groups can share the same median, Q1, and Q3 while one is a clean bell curve and the other is secretly bimodal — two clusters of customers, two manufacturing batches, two classes of students. A box plot hides that; a violin plot exposes it at a glance.
Why Use Violin Plots?
- Reveal multi-modal distributions. Unlike box plots, violin plots show when your data has multiple peaks.
- Compare shape, spread, and density. Place violin plots side by side to compare the entire distributional shape across groups.
- Combine with box plot elements. This tool overlays the five-number summary inside the violin.
- Spot skew and tail weight. Asymmetric violins and elongated tails are immediately visible.
- Communicate with technical audiences. Standard in genomics, ML model evaluation, and scientific publishing.
Worked Example: Reading a Bimodal Violin
Load the Bimodal Distribution sample (values cluster near 22–40 and again near 60–78). The summary statistics look unremarkable — median around 50, symmetric quartiles — and a box plot of the same data would look perfectly ordinary.
The violin tells the real story: the density narrows sharply near the median (a waist) and bulges twice, once in the low 30s and once in the high 60s. That waist is the signature of two overlapping subgroups. If this were exam data, you would suspect two classes with different preparation levels merged into one dataset.
To verify by hand: sort the data and look at the gap between the two clusters (no values between 40 and 60). Then compare with the histogram of the same sample — the two humps appear there too, confirming the violin's shape is real structure, not a smoothing artifact.
Common Misreadings
- Reading width as count. Width is relative density, not raw frequency — a violin of 20 points and one of 2,000 can look identical.
- Trusting the tails literally. KDE smoothing can extend the curve beyond the observed min/max. The overlaid box plot marks the true range.
- Over-interpreting tiny samples. With fewer than ~10 points, the wiggles in the density are mostly noise.
- Assuming one peak means normality. A single wide bulge can hide uniform data; cross-check with a histogram.
Frequently Asked Questions
What does a violin plot show?
How is a violin plot different from a box plot?
What is KDE and why does bandwidth matter?
When should I NOT use a violin plot?
Can a violin plot be misleading?
Key Terms
- KDE
- Kernel Density Estimation — a non-parametric way to estimate the probability density function.
- Bandwidth
- Controls the smoothness of the KDE curve. Smaller = finer detail; larger = smoother.
- Minimum (Min)
- The smallest data point excluding outliers.
- First Quartile (Q1)
- The median of the lower half. 25% of data falls below Q1.
- Median (Q2)
- The middle value. 50% of data falls below the median.
- Third Quartile (Q3)
- The median of the upper half. 75% of data falls below Q3.
- Maximum (Max)
- The largest data point excluding outliers.
- Interquartile Range
- Q3 − Q1. Measures statistical spread.
Computation Method
- Quartiles are calculated using linear interpolation (method 7 from Hyndman & Fan, 1996), consistent with Python's NumPy and pandas defaults.
- Outlier detection uses the Tukey fences method: lower fence = Q1 − 1.5 × IQR, upper fence = Q3 + 1.5 × IQR.
- Chart scaling caps the display axis at the upper fence value so the visualization remains clear even when extreme outliers are present.
References
- Hintze, J. L. & Nelson, R. D. (1998). "Violin Plots: A Box Plot-Density Trace Synergism." The American Statistician, 52(2), 181–184.
- Tukey, J. W. (1977). Exploratory Data Analysis. Addison-Wesley.
- Scott, D. W. (2015). Multivariate Density Estimation: Theory, Practice, and Visualization. 2nd ed. Wiley.