Tunny Icon
TunnyDocs

The next-gen Grasshopper optimization tool.

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:

f^(x)=1nhi=1nK ⁣(xxih)\hat{f}(x) = \frac{1}{n h} \sum_{i=1}^{n} K!\left(\frac{x - x_i}{h}\right)

Tunny Dashboard uses a Gaussian kernel K(t)=12πet2/2K(t) = \frac{1}{\sqrt{2\pi}} e^{-t^2/2} 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 hh 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:

h=1.06min(σ,IQR1.34)n1/5h = 1.06 \cdot \min\left(\sigma, \frac{\mathrm{IQR}}{1.34}\right) \cdot n^{-1/5}

The constant 1.061.06 is Scott's normal-reference factor and σ\sigma is the population standard deviation. The min(σ,IQR/1.34)\min(\sigma, \mathrm{IQR}/1.34) term is the robust part: the usual normal-reference form uses σ\sigma alone, but a single outlier can inflate σ\sigma 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 min\min 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.