Skip to content

Commit c44d6e8

Browse files
committed
Improve splom docs, fix parcat/parcoord docs
1 parent a175488 commit c44d6e8

File tree

3 files changed

+116
-25
lines changed

3 files changed

+116
-25
lines changed

docs/04_5_splom.fsx

Lines changed: 90 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,62 @@ let's first create some data for the purpose of creating example charts:
3333
3434
*)
3535

36-
open Plotly.NET
36+
37+
#r "nuget: FSharp.Data"
38+
#r "nuget: Deedle"
39+
40+
open FSharp.Data
41+
open Deedle
42+
open Plotly.NET
3743

3844
let data =
39-
[
40-
"A",[|1.;4.;3.4;0.7;|]
41-
"B",[|3.;1.5;1.7;2.3;|]
42-
"C",[|2.;4.;3.1;5.|]
43-
"D",[|4.;2.;2.;4.;|]
44-
]
45+
Http.RequestString @"https://raw.githubusercontent.com/plotly/datasets/master/iris-data.csv"
46+
|> fun csv -> Frame.ReadCsvString(csv,true,separators=",")
47+
48+
let sepalLengthData = data.["sepal length"] |> Series.values
49+
let sepalWidthData = data.["sepal width"] |> Series.values
50+
let petalLengthData = data.["petal length"] |> Series.values
51+
let petalWidthData = data.["petal width"] |> Series.values
52+
53+
let colors =
54+
data
55+
|> Frame.getCol "class"
56+
|> Series.values
57+
|> Seq.cast<string>
58+
|> Seq.map (fun x ->
59+
match x with
60+
| "Iris-setosa" -> 0.
61+
| "Iris-versicolor" -> 0.5
62+
| _ -> 1
63+
)
64+
|> Color.fromColorScaleValues
65+
4566

4667
(**
4768
Using a scatterplot matrix of several different variables can help to determine whether there are any
4869
relationships among the variables in the dataset.
4970
50-
**Attention**: this function is not very well tested and does not use the `Chart.Grid` functionality.
51-
Until that is fixed, consider creating splom plot programatically using `Chart.Grid` for more control.
71+
## Splom of the iris dataset
5272
*)
5373

54-
let splom1 =
55-
Chart.Splom(data,Color=Color.fromString "blue")
74+
let splom1 =
75+
Chart.Splom(
76+
[
77+
"sepal length" , sepalLengthData
78+
"sepal width" , sepalWidthData
79+
"petal length" , petalLengthData
80+
"petal width" , petalWidthData
81+
],
82+
MarkerColor = colors
83+
)
84+
|> Chart.withLayout(
85+
Layout.init(
86+
HoverMode = StyleParam.HoverMode.Closest,
87+
DragMode = StyleParam.DragMode.Select
88+
)
89+
)
90+
|> Chart.withSize (1000,1000)
91+
5692

5793
(*** condition: ipynb ***)
5894
#if IPYNB
@@ -63,7 +99,50 @@ splom1
6399
splom1 |> GenericChart.toChartHTML
64100
(***include-it-raw***)
65101

102+
(**
103+
## Showing different parts of the plot matrix
66104
105+
Use `ShowDiagonal`, `ShowUpperHalf` or `ShowLowerHalf` to customize the cells shown in the scatter plot matrix.
67106
107+
Here are some examples:
108+
*)
68109

110+
let noDiagonal =
111+
Chart.Splom(
112+
[
113+
"sepal length" , sepalLengthData
114+
"sepal width" , sepalWidthData
115+
"petal length" , petalLengthData
116+
"petal width" , petalWidthData
117+
],
118+
MarkerColor = colors,
119+
ShowDiagonal = false
120+
)
121+
|> Chart.withLayout(
122+
Layout.init(
123+
HoverMode = StyleParam.HoverMode.Closest,
124+
DragMode = StyleParam.DragMode.Select
125+
)
126+
)
127+
|> Chart.withSize (1000,1000)
128+
129+
130+
let noLowerHalf =
131+
Chart.Splom(
132+
[
133+
"sepal length" , sepalLengthData
134+
"sepal width" , sepalWidthData
135+
"petal length" , petalLengthData
136+
"petal width" , petalWidthData
137+
],
138+
MarkerColor = colors,
139+
ShowLowerHalf = false
140+
)
141+
|> Chart.withLayout(
142+
Layout.init(
143+
HoverMode = StyleParam.HoverMode.Closest,
144+
DragMode = StyleParam.DragMode.Select
145+
)
146+
)
147+
|> Chart.withSize (1000,1000)
69148

docs/09_0_parallel-categories.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ open Plotly.NET.TraceObjects
3838

3939
let dims =
4040
[
41-
Dimensions.init(["Cat1";"Cat1";"Cat1";"Cat1";"Cat2";"Cat2";"Cat3"],Label="A")
42-
Dimensions.init([0;1;0;1;0;0;0],Label="B",TickText=["YES";"NO"])
41+
Dimension.initParallel(Values = ["Cat1";"Cat1";"Cat1";"Cat1";"Cat2";"Cat2";"Cat3"],Label="A")
42+
Dimension.initParallel(Values = [0;1;0;1;0;0;0],Label="B",TickText=["YES";"NO"])
4343
]
4444

4545
let parcats =

docs/09_1_parallel-coords.fsx

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ the position of the vertex on the i-th axis corresponds to the i-th coordinate o
5353
*)
5454

5555
let parcoords1 =
56-
Chart.ParallelCoord(data,Color=Color.fromString "blue")
56+
Chart.ParallelCoord(data,Color=Color.fromString "blue", UseDefaults = false)
5757

5858
(*** condition: ipynb ***)
5959
#if IPYNB
@@ -67,26 +67,38 @@ parcoords1 |> GenericChart.toChartHTML
6767
open Plotly.NET.TraceObjects
6868

6969
// Dynamic object version
70+
7071
let parcoords =
7172
let v = [|
72-
Dimensions.init([|1.;4.;|],
73-
StyleParam.Range.MinMax (1.,5.),StyleParam.Range.MinMax (1.,2.),Label="A");
74-
Dimensions.init([|3.;1.5;|],
75-
StyleParam.Range.MinMax (1.,5.),Label="B",Tickvals=[|1.5;3.;4.;5.;|]);
76-
Dimensions.init([|2.;4.;|],
77-
StyleParam.Range.MinMax (1.,5.),Label="C",Tickvals=[|1.;2.;4.;5.;|],
78-
TickText=[|"txt 1";"txt 2";"txt 4";"txt 5";|]);
79-
Dimensions.init([|4.;2.;|],
80-
StyleParam.Range.MinMax (1.,5.),Label="D");
73+
Dimension.initParallel(
74+
Values = [|1.;4.;|],
75+
Range = StyleParam.Range.MinMax (1.,5.),
76+
ConstraintRange = StyleParam.Range.MinMax (1.,2.),
77+
Label="A");
78+
Dimension.initParallel(
79+
Values = [|3.;1.5;|],
80+
Range = StyleParam.Range.MinMax (1.,5.),
81+
Label="B",
82+
Tickvals=[|1.5;3.;4.;5.;|]);
83+
Dimension.initParallel(
84+
Values = [|2.;4.;|],
85+
Range = StyleParam.Range.MinMax (1.,5.),
86+
Label= "C",
87+
Tickvals=[|1.;2.;4.;5.;|],
88+
TickText=[|"txt 1";"txt 2";"txt 4";"txt 5";|]);
89+
Dimension.initParallel(
90+
Values = [|4.;2.;|],
91+
Range = StyleParam.Range.MinMax (1.,5.),
92+
Label="D");
8193
|]
8294

8395
let dyn = Trace("parcoords")
8496

8597
dyn?dimensions <- v
86-
dyn?line <- Line.init(Color=Color.fromString "blue")
98+
dyn?line <- Line.init(Color =Color.fromString "blue")
8799

88100
dyn
89-
|> GenericChart.ofTraceObject true
101+
|> GenericChart.ofTraceObject false
90102

91103
(*** condition: ipynb ***)
92104
#if IPYNB

0 commit comments

Comments
 (0)