-
Notifications
You must be signed in to change notification settings - Fork 81
/
09_1_parallel-coords.fsx
117 lines (88 loc) · 3.34 KB
/
09_1_parallel-coords.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
106
107
108
109
110
111
112
113
114
115
116
117
(**
---
title: Parallel coordinates
category: Categorical Charts
categoryindex: 10
index: 2
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 1.0.1"
#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
(**
# Parallel coordinates
[![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 parallel coordinates plot in F#.
let's first create some data for the purpose of creating example charts:
*)
open Plotly.NET
let data =
[
"A",[1.;4.;3.4;0.7;]
"B",[3.;1.5;1.7;2.3;]
"C",[2.;4.;3.1;5.]
"D",[4.;2.;2.;4.;]
]
(**
Parallel coordinates are a common way of visualizing high-dimensional geometry and analyzing multivariate data.
To show a set of points in an n-dimensional space, a backdrop is drawn consisting of n parallel lines, typically
vertical and equally spaced. A point in n-dimensional space is represented as a polyline with vertices on the parallel axes;
the position of the vertex on the i-th axis corresponds to the i-th coordinate of the point.
*)
let parcoords1 =
Chart.ParallelCoord(data,LineColor=Color.fromString "blue", UseDefaults = false)
(*** condition: ipynb ***)
#if IPYNB
parcoords1
#endif // IPYNB
(***hide***)
parcoords1 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## More styled example
This example shows the usage of some of the styling possibility using `Chart.ParallelCoord`.
For even more styling control, use the respective TraceStyle function `TraceDomainStyle.ParallelCoord`
*)
open Plotly.NET.TraceObjects
#r "nuget: FSharp.Data"
#r "nuget: Deedle"
open FSharp.Data
open Deedle
let parcoordsStyled =
let data =
"https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv"
|> Http.RequestString
|> Frame.ReadCsvString
let dims =
[
Dimension.initParallel(Label = "sepal_length", Values = (data |> Frame.getCol "sepal_length" |> Series.values), Range = StyleParam.Range.MinMax(0., 8.))
Dimension.initParallel(Label = "sepal_width" , Values = (data |> Frame.getCol "sepal_width" |> Series.values), Range = StyleParam.Range.MinMax(0., 8.))
Dimension.initParallel(Label = "petal_length", Values = (data |> Frame.getCol "petal_length" |> Series.values), Range = StyleParam.Range.MinMax(0., 8.))
Dimension.initParallel(Label = "petal_width" , Values = (data |> Frame.getCol "petal_width" |> Series.values), Range = StyleParam.Range.MinMax(0., 8.))
]
let colors =
data
|> Frame.getCol "species_id"
|> Series.values
|> Color.fromColorScaleValues
Chart.ParallelCoord(
dims,
LineColorScale = StyleParam.Colorscale.Viridis,
LineColor = colors
)
(*** condition: ipynb ***)
#if IPYNB
parcoordsStyled
#endif // IPYNB
(***hide***)
parcoordsStyled |> GenericChart.toChartHTML
(***include-it-raw***)