@@ -33,26 +33,62 @@ let's first create some data for the purpose of creating example charts:
33
33
34
34
*)
35
35
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
37
43
38
44
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
+
45
66
46
67
(**
47
68
Using a scatterplot matrix of several different variables can help to determine whether there are any
48
69
relationships among the variables in the dataset.
49
70
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
52
72
*)
53
73
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
+
56
92
57
93
(*** condition: ipynb ***)
58
94
#if IPYNB
@@ -63,7 +99,50 @@ splom1
63
99
splom1 |> GenericChart.toChartHTML
64
100
(***include-it-raw***)
65
101
102
+ (**
103
+ ## Showing different parts of the plot matrix
66
104
105
+ Use `ShowDiagonal`, `ShowUpperHalf` or `ShowLowerHalf` to customize the cells shown in the scatter plot matrix.
67
106
107
+ Here are some examples:
108
+ *)
68
109
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 )
69
148
0 commit comments