Violin Plot
Overview
A violin plot shows the estimated probability density of a numeric variable as a filled curve, mirrored around a central axis so it reads like a violin. The width of the curve at a given value is proportional to how likely that value is, so the shape of the distribution — its peaks, tails, and skew — is visible directly instead of being reduced to a few summary numbers.
It sits between the histogram and the box plot. Like a histogram it shows the shape of the distribution, including whether it has one peak or several; unlike a histogram it is a smooth continuous curve, so the apparent shape does not depend on a bin size. Like a box plot it can be lined up side by side for comparison; unlike a box plot, it does not discard the shape between the quartiles. It is worth reading alongside Histogram and Box Plot.
Kernel Density Estimation
The curve is a kernel density estimate (KDE). Each observation contributes a kernel — a smooth bump centred on its value — and the estimate is their average:
Tunny Dashboard uses a Gaussian kernel and evaluates the estimate on a fixed grid of 128 points spanning the data range plus two bandwidths at each end. Because the estimate is a sum of bumps, values that cluster in two places produce two peaks — exactly the multimodality a box plot cannot show.
Bandwidth
The bandwidth controls how wide each kernel is, and therefore how smooth the curve looks. Tunny Dashboard chooses it automatically with a robust variant of Scott's rule:
The constant is Scott's normal-reference factor and is the population standard deviation. The term is the robust part: the usual normal-reference form uses alone, but a single outlier can inflate and over-smooth the whole curve. Taking the smaller of the two spread estimates keeps the bandwidth close to the bulk of the data — the same idea as the Freedman–Diaconis rule for histograms. This form comes from Silverman's rule of thumb.
If the bandwidth is zero or non-finite — every value identical, or the spread collapsing to zero — a density estimate is not meaningful. Such a group is skipped and reported instead of being drawn.
Reading a Violin Plot
- A single peak means the values concentrate around one region; the peak's position is a robust read on the distribution's centre.
- Two or more peaks mean the values cluster into distinct groups. This is the main reason to prefer a violin plot over a box plot: two very different bimodal distributions can share the same five-number summary.
- A long, thin tail means rare values stretch the range. The curve stays narrow there because few observations support it.
- Comparison across violins: with every violin scaled to the same maximum width, a tall, narrow shape means the values are tightly concentrated, while a short, wide shape means they are spread out. Comparing widths is only meaningful because the scale is shared, and the app draws a median marker so the centre of each distribution stays visible.
Characteristics and Limitations
- The apparent shape depends on the bandwidth. A small bandwidth can reveal spurious bumps in small samples; a large one can merge genuine modes. The automatic rule is a starting point, not a definitive answer, so a shape that appears at only one bandwidth should be treated with care.
- The estimate is smoothed and can extend slightly beyond the smallest and largest observed values, because the grid spans two bandwidths past each end. The curve estimates the underlying distribution; it is not a record of the data.
- The equal-width scaling makes shapes comparable but hides sample size: a level with a handful of trials and a level with thousands both reach the same width. Check the trial counts when a difference looks important.
- A group needs at least two finite, non-identical values to estimate a density; smaller or constant groups are skipped.
Where It Is Used in the App
- Violin Plot widget: shows the density of each numeric objective or parameter side by side, or splits one numeric column by the levels of a categorical parameter. It is the first view to reach for when the shape of a distribution — especially whether it is multimodal — matters more than its mean or quartiles.
References
- Scott, D. W. (1979). On optimal and data-based histograms. Biometrika, 66(3), 605–610. https://doi.org/10.1093/biomet/66.3.605
- Silverman, B. W. (1986). Density Estimation for Statistics and Data Analysis. Chapman & Hall.
- Wand, M. P., & Jones, M. C. (1995). Kernel Smoothing. Chapman & Hall.