Tunny Icon
TunnyDocs

The next-gen Grasshopper optimization tool.

Violin Plot

Overview

The Violin Plot widget estimates the distribution of one selected numeric Value, optionally split into groups. Selection, category identity, finite-row alignment, and global normalization are the same as Box Plot. Categorical parameters and declared Optuna integer/stepped parameters can group the Value. Continuous parameters are not grouped or binned; numeric CSV parameters without distribution metadata are Value-only.

A violin mirrors a density curve around its group position. It reveals peaks, tails, skew, and multimodality that quartiles alone can hide.

Kernel density estimation

Each finite observation contributes a Gaussian kernel: \hat f(x)=\frac{1}{nh}\sum_{i=1}^n K!\left(\frac{x-x_i}{h}\right), \qquad K(t)=\frac{e^{-t^2/2}}{\sqrt{2\pi}}

The grid has 128 points spanning the group's observed minimum minus 2h2h to its maximum plus 2h2h. The density can therefore extend beyond the observations.

The automatic bandwidth is a robust variant of Scott's rule:

h=1.06 min⁡(σ,IQR1.34)n−1/5h=1.06,\min\left(\sigma,\frac{\mathrm{IQR}}{1.34}\right)n^{-1/5} σ\sigma is the population standard deviation, and IQR uses type-7 quartiles. If IQR is zero but σ>0\sigma>0, the spread falls back to σ\sigma so nonconstant samples with repeated values can still be estimated. Groups with fewer than two finite Values, constant Values, or non-finite/zero bandwidth are omitted and reported, including when all groups are omitted.

For more than 50,000 finite observations in a group, the sorted sample is deterministically subsampled to 50,000 evenly spaced observations, retaining both endpoints. KDE and its median marker use this sample.

Normalization and interpretation

Normalize transforms the entire finite selected Value column to [0,1] before grouping; constants become zero. There is no per-group normalization. KDE and exported grid/density values use that transformed scale.

Every violin reaches the same maximum width, regardless of group size. Its width at a particular Value shows density relative to that violin's peak, not trial count or a common absolute-density scale across groups. The median marker locates its centre. Different groups' bandwidths may differ; apparent modes in small samples should be interpreted cautiously.

  • One peak suggests concentration near one region; several peaks suggest modes.
  • Long, thin tails show rare values stretching the distribution.
  • For singleton or constant groups, use Box Plot rather than interpreting a fabricated density curve.
  • Group differences are descriptive, not proof of causation.

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.