TeeChart for RAD Studio – Kernel Density Estimator

Introduced in October 2019 in TeeChart for RAD Studio, the Kernel Density Estimation Function provides the basis for two series types:

  • Violin Series
  • BeeSwarm Series

The Kernel Density Estimation (KDE) Function

The Kernel Density Estimation (KDE) Function uses these parts:

  • Input Values
  • Position (the x offset)
  • Resolution
  • Bandwidth

If left to automatically clamp the data, the KDE function checks highs and lows from the input data to set min and max limits. The values can be manually overridden.

A full definition of KDE here:

In simpler terms, with respect to usability in TeeChart; the KDE uses the Resolution value to set the output Y value range and scans the input data for the mean of the input kernel values with respect output Y. Increasing the KDE Bandwidth value reduces sensitivity and ‘smooths’.

The Violin Series

The Violin Series is loyal representation of KDE as a series of polygonesque shapes, where each shape emerges with displacements of greater than 0 from the KDE position.

Often shown with the given Box plot for the corresponding data, here are three examples of the Violin series, that uses KDE, show the same data with low and higher bandwidth and resolution settings:

TeeChart Violin KDE

TeeChart Violin KDE

TeeChart Violin KDE

The BeeSwarm Series

The BeeSwarm Series has a few underlying differences to the Violin Series apart from the general appearance. Its plot consists of points and it uses the point size to define the resolution that limits the number of point rows across the vertical range; the points that fit according to point size without overlapping. BeeSwarm checks value cluster-densities with respect to Point row Y locations and brings the values into the rows, ‘swarming’ them.

The following two charts show the difference that varying the point size makes on the number of BeeSwarm rows.

4×4 pixel points

8×8 pixel points

Setting up the Violin and BeeSwarm plots

You can use the TeeChart Editor but here’s a code example. The key is simply to load data to the Violin’s input. That could take the form of Datasource, where the datasource is, for example, a Series with a Y-valuelist.

Create the Series
uses TeeBoxPlot

violin := TViolinSeries.Create(self);

Add data to the source Series. If the source is a Boxplot Series then you’ll be settingthe Position. The Violin and BeeSwarm use the Position:

MyBoxPlotSeries.Position := 2019;

Set up the Datasource for the Violin and refresh data.

violin.DataSource := MyBoxPlotSeries;

Optionally you can pass a valuelist directly to the Violin Series.


The techniques are identical for BeeSwarm.

Leave a Reply

Your email address will not be published. Required fields are marked *