Violin plots
A violin plot is another way to compare multiple distributions of numerical variables. It is similar to a box plot, but a distribution is shown rather than (or, in addition to) the boxes. You can create a violin plot using the Plot.Create.ViolinPlot
method:
Like the Plot.Create.BoxPlot
method, this method has three overloads, differing in the type of the first parameter they accept. The first overload (used in the example above) takes an IReadOnlyList<(T, IReadOnlyList<double>)>
; each element in this array consists of a T
whose ToString
method is used to determine the labels, and an IReadOnlyList<double>
containing the elements whose distribution is displayed by the violin plot. This method has a number of optional parameters that can be used to determine the appearance of some elements of the plot. Many of these are in common with other kinds of plots and are described in the page about scatter plots; here are the ones specific for violin plots:
bool proportionalWidth
: if this isfalse
(the default), all violins have the same width. If this istrue
, the width of each violin in the plot is proportional to the number of samples.bool smooth
: if thistrue
(the default), the distributions are smoothed by drawing a spline curve that passes through each point. If this isfalse
, straight line segments are drawn.Violin.ViolinSide sides
: this parameter determines whether the violins should be drawn on the left, on the right, or both (the default).bool showBoxPlots
: if this istrue
(the default), a small box plot is drawn together with each violin. Otherwise, only the violins are drawn.double violinWidth
: this parameter determines the width of the violins in the data space. You probably do not want to change this.double boxWidth
: this parameter determines the width of the boxes (ifshowBoxPlots
istrue
), relative to the width of the violins.double spacing
: this determines the amount of spacing between consecutive violins.double? dataRangeMin
: this parameter determines the minimum value shown on the data value axis. If this isnull
(the default), this is determined from the data. Providing a value for this parameter is useful if you wish to create multiple plots with the same range of values.double? dataRangeMax
: this parameter determines the maximum value shown on the data value axis. If this isnull
(the default), this is determined from the data. Providing a value for this parameter is useful if you wish to create multiple plots with the same range of values.bool vertical
: if this istrue
(the default), the violins are oriented vertically and parallel to theY
axis. If this isfalse
, the violins are horizontal.IReadOnlyList<PlotElementPresentationAttributes> violinPresentationAttributes
: this determines the appearance (stroke, fill, etc) of the violins.IReadOnlyList<PlotElementPresentationAttributes> boxPresentationAttributes
: this determines the appearance (stroke, fill, etc) of the boxes and whiskers.IReadOnlyList<PlotElementPresentationAttributes> medianPresentationAttributes
: this determines the appearance (stroke, fill, etc) of the symbols used to highlight the median in the box plots.IDataPointElement medianSymbol
: this determines the symbol used to highlight the median in the box plots.
The second overload for this method takes a first parameter of type IReadOnlyList<IReadOnlyList<double>>
, and draws a violin plot without labels on the X
axis. The optional parameters for this overload are the same as the previous overload. Finally, the third overload for this method takes a first parameter of type IReadOnlyList<double>
and draws a single violin in the plot. This overload does not have the proportionalWidth
and spacing
parameters.
Note that in all cases, the distributions drawn here are “histograms in disguise” (see the page about distribution plots) and not kernel density estimations.
The following example shows the effect of some of these optional parameters on the plot: