-
Notifications
You must be signed in to change notification settings - Fork 81
/
04_2_violin-plots.fsx
107 lines (82 loc) · 2.53 KB
/
04_2_violin-plots.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
(**
---
title: Violin plots
category: Distribution Charts
categoryindex: 5
index: 3
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#r "nuget: DynamicObj"
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# Violin plots
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
*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
)
(*** condition: ipynb ***)
#if IPYNB
violin1
#endif // IPYNB
(***hide***)
violin1 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
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)
)
(*** condition: ipynb ***)
#if IPYNB
violin2
#endif // IPYNB
(***hide***)
violin2 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
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
(*** condition: ipynb ***)
#if IPYNB
violin3
#endif // IPYNB
(***hide***)
violin3 |> GenericChart.toChartHTML
(***include-it-raw***)