Violin plots

BinderScriptNotebook

Summary: This example shows how to create violin plot charts in F#.

let's first create some data for the purpose of creating example charts:

open Plotly.NET 
  
let y =  [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
let x = ["bin1";"bin2";"bin1";"bin2";"bin1";"bin2";"bin1";"bin1";"bin2";"bin1"]

A violin plot is a method of plotting numeric data. It is similar to box plot with a rotated kernel density plot on each side. The violin plot is similar to box plots, except that they also show the probability density of the data at different values.

let violin1 =
    Chart.Violin (
        x,y,
        Points=StyleParam.Jitterpoints.All
    )

By swapping x and y plus using StyleParam.Orientation.Horizontal we can flip the chart horizontaly.

open Plotly.NET.TraceObjects

let violin2 =
    Chart.Violin(
        y,x,
        Jitter=0.1,
        Points=StyleParam.Jitterpoints.All,
        Orientation=StyleParam.Orientation.Horizontal,
        Meanline=Meanline.init(Visible=true)
    )

You can also produce a violin plot using the Chart.Combine syntax.

let y' =  [2.; 1.5; 5.; 1.5; 2.; 2.5; 2.1; 2.5; 1.5; 1.;2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]

let violin3 =
    [
        Chart.Violin ("y" ,y,Name="bin1",Jitter=0.1,Points=StyleParam.Jitterpoints.All);
        Chart.Violin ("y'",y',Name="bin2",Jitter=0.1,Points=StyleParam.Jitterpoints.All);
    ]
    |> Chart.combine
namespace Plotly
namespace Plotly.NET
val y : float list
val x : string list
val violin1 : GenericChart.GenericChart
type Chart = static member Area : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?ShowLegend:bool * ?MarkerSymbol:MarkerSymbol * ?Color:Color * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:float -> GenericChart + 1 overload static member Bar : values:seq<#IConvertible> * ?Keys:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?PatternShape:PatternShape * ?MultiPatternShape:seq<PatternShape> * ?Pattern:Pattern * ?Base:#IConvertible * ?Width:'a3 * ?MultiWidth:seq<'a3> * ?Opacity:float * ?MultiOpacity:seq<float> * ?Text:'a4 * ?MultiText:seq<'a4> * ?TextPosition:TextPosition * ?MultiTextPosition:seq<TextPosition> * ?TextFont:Font * ?Marker:Marker -> GenericChart (requires 'a3 :> IConvertible and 'a4 :> IConvertible) + 1 overload static member BoxPlot : ?x:'a0 * ?y:'a1 * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Whiskerwidth:'a2 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a3 * ?Pointpos:'a4 * ?Orientation:Orientation * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a5 * ?Offsetgroup:'a6 * ?Notched:bool * ?NotchWidth:float * ?QuartileMethod:QuartileMethod -> GenericChart + 1 overload static member Bubble : x:seq<#IConvertible> * y:seq<#IConvertible> * sizes:seq<int> * ?Name:string * ?ShowLegend:bool * ?MarkerSymbol:MarkerSymbol * ?Color:Color * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:Orientation * ?GroupNorm:GroupNorm * ?UseWebGL:bool -> GenericChart + 1 overload static member Candlestick : open:seq<#IConvertible> * high:seq<#IConvertible> * low:seq<#IConvertible> * close:seq<#IConvertible> * x:seq<#IConvertible> * ?Increasing:Line * ?Decreasing:Line * ?WhiskerWidth:float * ?Line:Line * ?XCalendar:Calendar -> GenericChart + 1 overload static member Column : values:seq<#IConvertible> * ?Keys:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Pattern:Pattern * ?PatternShape:PatternShape * ?MultiPatternShape:seq<PatternShape> * ?Base:#IConvertible * ?Width:'a3 * ?MultiWidth:seq<'a3> * ?Opacity:float * ?MultiOpacity:seq<float> * ?Text:'a4 * ?MultiText:seq<'a4> * ?TextPosition:TextPosition * ?MultiTextPosition:seq<TextPosition> * ?TextFont:Font * ?Marker:Marker -> GenericChart (requires 'a3 :> IConvertible and 'a4 :> IConvertible) + 1 overload static member Contour : data:seq<#seq<'a1>> * ?X:seq<#IConvertible> * ?Y:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'a4 * ?zSmooth:SmoothAlg * ?ColorBar:'a5 -> GenericChart (requires 'a1 :> IConvertible) static member Funnel : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Color:Color * ?Line:Line * ?x0:'a3 * ?dX:float * ?y0:'a4 * ?dY:float * ?Width:float * ?Offset:float * ?Orientation:Orientation * ?Alignmentgroup:string * ?Offsetgroup:string * ?Cliponaxis:bool * ?Connector:FunnelConnector * ?Insidetextfont:Font * ?Outsidetextfont:Font -> GenericChart static member Heatmap : data:seq<#seq<'a1>> * ?ColNames:seq<#IConvertible> * ?RowNames:seq<#IConvertible> * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'a4 * ?Xgap:'a5 * ?Ygap:'a6 * ?zSmooth:SmoothAlg * ?ColorBar:'a7 * ?UseWebGL:bool -> GenericChart (requires 'a1 :> IConvertible) static member Histogram : data:seq<#IConvertible> * ?Orientation:Orientation * ?Name:string * ?ShowLegend:bool * ?Opacity:float * ?Color:Color * ?HistNorm:HistNorm * ?HistFunc:HistFunc * ?nBinsx:int * ?nBinsy:int * ?Xbins:Bins * ?Ybins:Bins * ?xError:'a1 * ?yError:'a2 -> GenericChart ...
static member Chart.Violin : xy:seq<'a0 * 'a1> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Points:StyleParam.Boxpoints * ?Jitter:'a2 * ?Pointpos:'a3 * ?Orientation:StyleParam.Orientation * ?Width:'a4 * ?Marker:TraceObjects.Marker * ?Line:Line * ?Alignmentgroup:'a5 * ?Offsetgroup:'a6 * ?Box:TraceObjects.Box * ?Bandwidth:'a7 * ?Meanline:TraceObjects.Meanline * ?Scalegroup:'a8 * ?Scalemode:'a9 * ?Side:'a10 * ?Span:'a11 * ?SpanMode:'a12 * ?Uirevision:'a13 -> GenericChart.GenericChart
static member Chart.Violin : ?x:'a * ?y:'b * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Points:StyleParam.Boxpoints * ?Jitter:'c * ?Pointpos:'d * ?Orientation:StyleParam.Orientation * ?Width:'e * ?Marker:TraceObjects.Marker * ?Line:Line * ?Alignmentgroup:'f * ?Offsetgroup:'g * ?Box:TraceObjects.Box * ?Bandwidth:'h * ?Meanline:TraceObjects.Meanline * ?Scalegroup:'i * ?Scalemode:'j * ?Side:'k * ?Span:'l * ?SpanMode:'m * ?Uirevision:'n -> GenericChart.GenericChart
module StyleParam from Plotly.NET
type Jitterpoints = StyleParam.Boxpoints
union case StyleParam.Boxpoints.All: StyleParam.Boxpoints
module GenericChart from Plotly.NET
<summary> Module to represent a GenericChart </summary>
val toChartHTML : gChart:GenericChart.GenericChart -> string
<summary> Converts a GenericChart to it HTML representation. The div layer has a default size of 600 if not specified otherwise. </summary>
namespace Plotly.NET.TraceObjects
val violin2 : GenericChart.GenericChart
static member Chart.Violin : xy:seq<'a0 * 'a1> * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Points:StyleParam.Boxpoints * ?Jitter:'a2 * ?Pointpos:'a3 * ?Orientation:StyleParam.Orientation * ?Width:'a4 * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a5 * ?Offsetgroup:'a6 * ?Box:Box * ?Bandwidth:'a7 * ?Meanline:Meanline * ?Scalegroup:'a8 * ?Scalemode:'a9 * ?Side:'a10 * ?Span:'a11 * ?SpanMode:'a12 * ?Uirevision:'a13 -> GenericChart.GenericChart
static member Chart.Violin : ?x:'a * ?y:'b * ?Name:string * ?ShowLegend:bool * ?Color:Color * ?Fillcolor:Color * ?Opacity:float * ?Points:StyleParam.Boxpoints * ?Jitter:'c * ?Pointpos:'d * ?Orientation:StyleParam.Orientation * ?Width:'e * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'f * ?Offsetgroup:'g * ?Box:Box * ?Bandwidth:'h * ?Meanline:Meanline * ?Scalegroup:'i * ?Scalemode:'j * ?Side:'k * ?Span:'l * ?SpanMode:'m * ?Uirevision:'n -> GenericChart.GenericChart
type Orientation = | Horizontal | Vertical member Convert : unit -> obj override ToString : unit -> string static member convert : (Orientation -> obj) static member toString : (Orientation -> string)
union case StyleParam.Orientation.Horizontal: StyleParam.Orientation
Multiple items
type Meanline = inherit DynamicObj new : unit -> Meanline static member init : ?Visible:bool * ?Color:Color * ?Width:float -> Meanline static member style : ?Visible:bool * ?Color:Color * ?Width:float -> (Meanline -> Meanline)
<summary> Meanline type inherits from dynamic object (parent violin) </summary>

--------------------
new : unit -> Meanline
static member Meanline.init : ?Visible:bool * ?Color:Color * ?Width:float -> Meanline
val y' : float list
val violin3 : GenericChart.GenericChart
static member Chart.combine : gCharts:seq<GenericChart.GenericChart> -> GenericChart.GenericChart