-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathChart2D_Splom.fs
More file actions
478 lines (439 loc) · 25.6 KB
/
Chart2D_Splom.fs
File metadata and controls
478 lines (439 loc) · 25.6 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
namespace Plotly.NET
open Plotly.NET.LayoutObjects
open Plotly.NET.TraceObjects
open DynamicObj
open System
open System.IO
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
[<AutoOpen>]
module Chart2D_Splom =
[<Extension>]
type Chart =
/// <summary>
/// Creates a scatter plot matrix (SPLOM) from multiple input dimensions.
///
/// Each splom `dimensions` items correspond to a generated axis. Values for each of those dimensions are set in `dimensions[i].values`. Splom traces support all `scattergl` marker style attributes. Specify `layout.grid` attributes and/or layout x-axis and y-axis attributes for more control over the axis positioning and style.
/// </summary>
/// <param name="dimensions">Sets the dimensions of the scatter plot matrix, where each item corresponds to a generated axis.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover.</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the Opacity otf the trace.</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="MarkerColor">Sets the color of the marker.</param>
/// <param name="MarkerColorScale">Sets the colorscale of the marker. Use `Color.fromColorScaleValues` to map marker colors to a colorscale.</param>
/// <param name="MarkerOutline">Sets the outline of the marker</param>
/// <param name="MarkerSymbol">Sets the symbol of all marker</param>
/// <param name="MultiMarkerSymbol">Sets the symbol of each individual marker</param>
/// <param name="Marker">Sets the markers (use this for more finegrained control than the other marker-associated arguments).</param>
/// <param name="ShowDiagonal">Whether or not to show the matrix diagional</param>
/// <param name="Diagonal">Sets the styles applied to the scatter plot matrix diagonal</param>
/// <param name="ShowLowerHalf">Determines whether or not subplots on the lower half from the diagonal are displayed.</param>
/// <param name="ShowUpperHalf">Determines whether or not subplots on the upper half from the diagonal are displayed.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Splom
(
dimensions: seq<Dimension>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?MarkerColor: Color,
?MarkerColorScale: StyleParam.Colorscale,
?MarkerOutline: Line,
?MarkerSymbol: StyleParam.MarkerSymbol,
?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
?Marker: Marker,
?ShowDiagonal: bool,
?Diagonal: SplomDiagonal,
?ShowLowerHalf: bool,
?ShowUpperHalf: bool,
?UseDefaults: bool
) =
let useDefaults =
defaultArg UseDefaults true
let marker =
Marker
|> Option.defaultValue (TraceObjects.Marker.init ())
|> TraceObjects.Marker.style (
?Color = MarkerColor,
?Outline = MarkerOutline,
?Symbol = MarkerSymbol,
?MultiSymbol = MultiMarkerSymbol,
?Colorscale = MarkerColorScale
)
let diagonal =
Diagonal
|> Option.defaultValue (TraceObjects.SplomDiagonal.init ())
|> TraceObjects.SplomDiagonal.style (?Visible = ShowDiagonal)
Trace2D.initSplom (
Trace2DStyle.Splom(
Dimensions = dimensions,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
Marker = marker,
Diagonal = diagonal,
?ShowLowerHalf = ShowLowerHalf,
?ShowUpperHalf = ShowUpperHalf
)
)
|> GenericChart.ofTraceObject useDefaults
/// <summary>
/// Creates a scatter plot matrix (SPLOM) from multiple input dimensions.
///
/// Each splom `dimensions` items correspond to a generated axis. Values for each of those dimensions are set in `dimensions[i].values`. Splom traces support all `scattergl` marker style attributes. Specify `layout.grid` attributes and/or layout x-axis and y-axis attributes for more control over the axis positioning and style.
/// </summary>
/// <param name="keyValues">Sets the dimensions of the scatter plot matrix as (dimensionKey,dimensionValues) pairs, where each such pair corresponds to a generated axis.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover.</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the Opacity otf the trace.</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="MarkerColor">Sets the color of the marker.</param>
/// <param name="MarkerColorScale">Sets the colorscale of the marker. Use `Color.fromColorScaleValues` to map marker colors to a colorscale.</param>
/// <param name="MarkerOutline">Sets the outline of the marker</param>
/// <param name="MarkerSymbol">Sets the symbol of all marker</param>
/// <param name="MultiMarkerSymbol">Sets the symbol of each individual marker</param>
/// <param name="Marker">Sets the markers (use this for more finegrained control than the other marker-associated arguments).</param>
/// <param name="ShowDiagonal">Whether or not to show the matrix diagional</param>
/// <param name="Diagonal">Sets the styles applied to the scatter plot matrix diagonal</param>
/// <param name="ShowLowerHalf">Determines whether or not subplots on the lower half from the diagonal are displayed.</param>
/// <param name="ShowUpperHalf">Determines whether or not subplots on the upper half from the diagonal are displayed.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Splom
(
keyValues: seq<string * #seq<#IConvertible>>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?MarkerColor: Color,
?MarkerColorScale: StyleParam.Colorscale,
?MarkerOutline: Line,
?MarkerSymbol: StyleParam.MarkerSymbol,
?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
?Marker: Marker,
?ShowDiagonal: bool,
?Diagonal: SplomDiagonal,
?ShowLowerHalf: bool,
?ShowUpperHalf: bool,
?UseDefaults: bool
) =
let dims =
keyValues |> Seq.map (fun (key, vals) -> Dimension.initSplom (Label = key, Values = vals))
Chart.Splom(
dims,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?MarkerColor = MarkerColor,
?MarkerColorScale = MarkerColorScale,
?MarkerOutline = MarkerOutline,
?MarkerSymbol = MarkerSymbol,
?MultiMarkerSymbol = MultiMarkerSymbol,
?Marker = Marker,
?ShowDiagonal = ShowDiagonal,
?Diagonal = Diagonal,
?ShowLowerHalf = ShowLowerHalf,
?ShowUpperHalf = ShowUpperHalf,
?UseDefaults = UseDefaults
)
/// <summary>
/// Creates a scatter plot matrix (SPLOM) from multiple encoded input dimensions.
///
/// Each splom dimension is provided as a pair of a dimension label and an encoded typed array containing that dimension's values.
/// Splom traces support all `scattergl` marker style attributes. Specify `layout.grid` attributes and/or layout x-axis and y-axis attributes for more control over the axis positioning and style.
/// </summary>
/// <param name="keyValuesEncoded">Sets the dimensions of the scatter plot matrix as (dimensionKey, encodedDimensionValues) pairs, where each such pair corresponds to a generated axis.</param>
/// <param name="Name">Sets the trace name. The trace name appear as the legend item and on hover.</param>
/// <param name="ShowLegend">Determines whether or not an item corresponding to this trace is shown in the legend.</param>
/// <param name="Opacity">Sets the Opacity otf the trace.</param>
/// <param name="Text">Sets a text associated with each datum</param>
/// <param name="MultiText">Sets individual text for each datum</param>
/// <param name="MarkerColor">Sets the color of the marker.</param>
/// <param name="MarkerColorScale">Sets the colorscale of the marker. Use `Color.fromColorScaleValues` to map marker colors to a colorscale.</param>
/// <param name="MarkerOutline">Sets the outline of the marker</param>
/// <param name="MarkerSymbol">Sets the symbol of all marker</param>
/// <param name="MultiMarkerSymbol">Sets the symbol of each individual marker</param>
/// <param name="Marker">Sets the markers (use this for more finegrained control than the other marker-associated arguments).</param>
/// <param name="ShowDiagonal">Whether or not to show the matrix diagional</param>
/// <param name="Diagonal">Sets the styles applied to the scatter plot matrix diagonal</param>
/// <param name="ShowLowerHalf">Determines whether or not subplots on the lower half from the diagonal are displayed.</param>
/// <param name="ShowUpperHalf">Determines whether or not subplots on the upper half from the diagonal are displayed.</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member Splom
(
keyValuesEncoded: seq<string * EncodedTypedArray>,
?Name: string,
?ShowLegend: bool,
?Opacity: float,
?Text: #IConvertible,
?MultiText: seq<#IConvertible>,
?MarkerColor: Color,
?MarkerColorScale: StyleParam.Colorscale,
?MarkerOutline: Line,
?MarkerSymbol: StyleParam.MarkerSymbol,
?MultiMarkerSymbol: seq<StyleParam.MarkerSymbol>,
?Marker: Marker,
?ShowDiagonal: bool,
?Diagonal: SplomDiagonal,
?ShowLowerHalf: bool,
?ShowUpperHalf: bool,
?UseDefaults: bool
) =
let dims =
keyValuesEncoded
|> Seq.map (fun (key, encodedVals) -> Dimension.initSplom (Label = key, ValuesEncoded = encodedVals))
Chart.Splom(
dims,
?Name = Name,
?ShowLegend = ShowLegend,
?Opacity = Opacity,
?Text = Text,
?MultiText = MultiText,
?MarkerColor = MarkerColor,
?MarkerColorScale = MarkerColorScale,
?MarkerOutline = MarkerOutline,
?MarkerSymbol = MarkerSymbol,
?MultiMarkerSymbol = MultiMarkerSymbol,
?Marker = Marker,
?ShowDiagonal = ShowDiagonal,
?Diagonal = Diagonal,
?ShowLowerHalf = ShowLowerHalf,
?ShowUpperHalf = ShowUpperHalf,
?UseDefaults = UseDefaults
)
/// <summary>
/// Creates a point density plot - a combination of a Scatter plot and Histogram2DContour.
///
/// Additionally to plotting the (x,y) data as points on a 2D plane, a density contour plot is computed by grouping a set of points specified by their x and y coordinates into bins, and applying a count aggregation function to compute the value to be used to compute contours.
/// The sample data from which statistics are computed is set in `x` and `y` (where `x` and `y` represent marginal distributions, binning is set in `xbins` and `ybins` in this case). The resulting distribution is visualized as a contour plot.
///
/// </summary>
/// <param name="x">Sets the x coordinates of the plotted data as well as the sample data to be binned on the x axis.</param>
/// <param name="y">Sets the y coordinates of the plotted data as well as the sample data to be binned on the y axis.</param>
/// <param name="PointOpacity">Sets the opacity of the point trace.</param>
/// <param name="PointMarkerColor">Sets the marker color of the point trace.</param>
/// <param name="PointMarkerSymbol">Sets the marker symbol of the point trace.</param>
/// <param name="PointMarkerSize">Sets the marker size of the point trace.</param>
/// <param name="ContourLinesDash">Sets the contour line dash style</param>
/// <param name="ContourLinesColor">Sets the contour line color</param>
/// <param name="ContourLinesSmoothing">Sets the amount of smoothing for the contour lines, where "0" corresponds to no smoothing.</param>
/// <param name="ContourLinesWidth">Sets the width of the contour lines</param>
/// <param name="ContourLines">Sets the contour lines (use this for more finegrained control than the other contourline-associated arguments).</param>
/// <param name="ShowContourLines">Wether or not to show the contour line</param>
/// <param name="ContoursColoring">Determines the coloring method showing the contour values. If "fill", coloring is done evenly between each contour level If "heatmap", a heatmap gradient coloring is applied between each contour level. If "lines", coloring is done on the contour lines. If "none", no coloring is applied on this trace.</param>
/// <param name="ContoursOperation">Sets the constraint operation. "=" keeps regions equal to `value` "<" and "<=" keep regions less than `value` ">" and ">=" keep regions greater than `value` "[]", "()", "[)", and "(]" keep regions inside `value[0]` to `value[1]` "][", ")(", "](", ")[" keep regions outside `value[0]` to value[1]` Open vs. closed intervals make no difference to constraint display, but all versions are allowed for consistency with filter transforms.</param>
/// <param name="ContoursType">If `levels`, the data is represented as a contour plot with multiple levels displayed. If `constraint`, the data is represented as constraints with the invalid region shaded as specified by the `operation` and `value` parameters.</param>
/// <param name="ShowContoursLabels">Determines whether to label the contour lines with their values.</param>
/// <param name="ContoursLabelFont">Sets the font used for labeling the contour levels. The default color comes from the lines, if shown. The default family and size come from `layout.font`.</param>
/// <param name="ContoursStart">Sets the starting contour level value. Must be less than `contours.end`</param>
/// <param name="ContoursEnd">Sets the end contour level value. Must be more than `contours.start`</param>
/// <param name="Contours">Sets the styles of the contours (use this for more finegrained control than the other contour-associated arguments).</param>
/// <param name="NContours">Sets the maximum number of contour levels. The actual number of contours will be chosen automatically to be less than or equal to the value of `ncontours`. Has an effect only if `autocontour` is "true" or if `contours.size` is missing.</param>
/// <param name="HistNorm">Specifies the type of normalization used for this histogram trace. If "", the span of each bar corresponds to the number of occurrences (i.e. the number of data points lying inside the bins). If "percent" / "probability", the span of each bar corresponds to the percentage / fraction of occurrences with respect to the total number of sample points (here, the sum of all bin HEIGHTS equals 100% / 1). If "density", the span of each bar corresponds to the number of occurrences in a bin divided by the size of the bin interval (here, the sum of all bin AREAS equals the total number of sample points). If "probability density", the area of each bar corresponds to the probability that an event will fall into the corresponding bin (here, the sum of all bin AREAS equals 1).</param>
/// <param name="ContourOpacity">Sets the opacity of the histogram2dcontour trace.</param>
/// <param name="ColorBar">Sets the color bar.</param>
/// <param name="ColorScale">Sets the colorscale of the histogram2dcontour trace.</param>
/// <param name="ShowScale">whether or not to show the colorbar</param>
/// <param name="UseDefaults">If set to false, ignore the global default settings set in `Defaults`</param>
[<Extension>]
static member PointDensity
(
x: seq<#IConvertible>,
y: seq<#IConvertible>,
?PointOpacity: float,
?PointMarkerColor: Color,
?PointMarkerSymbol: StyleParam.MarkerSymbol,
?PointMarkerSize: int,
?ContourLinesColor: Color,
?ContourLinesDash: StyleParam.DrawingStyle,
?ContourLinesSmoothing: float,
?ContourLinesWidth: float,
?ContourLines: Line,
?ShowContourLines: bool,
?ContoursColoring: StyleParam.ContourColoring,
?ContoursOperation: StyleParam.ConstraintOperation,
?ContoursType: StyleParam.ContourType,
?ShowContoursLabels: bool,
?ContoursLabelFont: Font,
?ContoursStart: float,
?ContoursEnd: float,
?Contours: Contours,
?NContours: int,
?HistNorm: StyleParam.HistNorm,
?ContourOpacity: float,
?ColorBar: ColorBar,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?UseDefaults: bool
) =
let showContourLines =
defaultArg ShowContourLines false
let pointOpacity =
defaultArg PointOpacity 0.3
let contoursColoring =
defaultArg ContoursColoring StyleParam.ContourColoring.Fill
let useDefaults =
defaultArg UseDefaults true
let contourLinesWidth =
ContourLinesWidth |> Option.map (fun v -> if showContourLines then v else 0.) |> Option.defaultValue 0.
let marker =
Marker.init (?Color = PointMarkerColor, ?Symbol = PointMarkerSymbol, ?Size = PointMarkerSize)
let pointTrace =
Trace2D.initScatter (
Trace2DStyle.Scatter(
X = x,
Y = y,
Mode = StyleParam.Mode.Markers,
Marker = marker,
Opacity = pointOpacity
)
)
let contourLines =
ContourLines
|> Option.defaultValue (Plotly.NET.Line.init ())
|> Plotly.NET.Line.style (
Width = contourLinesWidth,
?Color = ContourLinesColor,
?Dash = ContourLinesDash,
?Smoothing = ContourLinesSmoothing
)
let contours =
Contours
|> Option.defaultValue (TraceObjects.Contours.init ())
|> TraceObjects.Contours.style (
Coloring = contoursColoring,
?Operation = ContoursOperation,
?Start = ContoursStart,
?End = ContoursEnd,
?Type = ContoursType,
?ShowLabels = ShowContoursLabels,
?LabelFont = ContoursLabelFont
)
let densityContourTrace =
Trace2D.initHistogram2DContour (
Trace2DStyle.Histogram2DContour(
X = x,
Y = y,
Contours = contours,
Line = contourLines,
?NContours = NContours,
?ColorBar = ColorBar,
?ColorScale = ColorScale,
?ShowScale = ShowScale,
?HistNorm = HistNorm,
?Opacity = ContourOpacity
)
)
[
densityContourTrace :> Trace
pointTrace :> Trace
]
|> GenericChart.ofTraceObjects useDefaults
/// <summary>Creates a point density plot from encoded x and y coordinates.</summary>
[<Extension>]
static member PointDensity
(
xEncoded: EncodedTypedArray,
yEncoded: EncodedTypedArray,
?PointOpacity: float,
?PointMarkerColor: Color,
?PointMarkerSymbol: StyleParam.MarkerSymbol,
?PointMarkerSize: int,
?ContourLinesColor: Color,
?ContourLinesDash: StyleParam.DrawingStyle,
?ContourLinesSmoothing: float,
?ContourLinesWidth: float,
?ContourLines: Line,
?ShowContourLines: bool,
?ContoursColoring: StyleParam.ContourColoring,
?ContoursOperation: StyleParam.ConstraintOperation,
?ContoursType: StyleParam.ContourType,
?ShowContoursLabels: bool,
?ContoursLabelFont: Font,
?ContoursStart: float,
?ContoursEnd: float,
?Contours: Contours,
?NContours: int,
?HistNorm: StyleParam.HistNorm,
?ContourOpacity: float,
?ColorBar: ColorBar,
?ColorScale: StyleParam.Colorscale,
?ShowScale: bool,
?UseDefaults: bool
) =
let showContourLines =
defaultArg ShowContourLines false
let pointOpacity =
defaultArg PointOpacity 0.3
let contoursColoring =
defaultArg ContoursColoring StyleParam.ContourColoring.Fill
let useDefaults =
defaultArg UseDefaults true
let contourLinesWidth =
ContourLinesWidth |> Option.map (fun v -> if showContourLines then v else 0.) |> Option.defaultValue 0.
let marker =
Marker.init (?Color = PointMarkerColor, ?Symbol = PointMarkerSymbol, ?Size = PointMarkerSize)
let pointTrace =
Trace2D.initScatter (
Trace2DStyle.Scatter(
XEncoded = xEncoded,
YEncoded = yEncoded,
Mode = StyleParam.Mode.Markers,
Marker = marker,
Opacity = pointOpacity
)
)
let contourLines =
ContourLines
|> Option.defaultValue (Plotly.NET.Line.init ())
|> Plotly.NET.Line.style (
Width = contourLinesWidth,
?Color = ContourLinesColor,
?Dash = ContourLinesDash,
?Smoothing = ContourLinesSmoothing
)
let contours =
Contours
|> Option.defaultValue (TraceObjects.Contours.init ())
|> TraceObjects.Contours.style (
Coloring = contoursColoring,
?Operation = ContoursOperation,
?Start = ContoursStart,
?End = ContoursEnd,
?Type = ContoursType,
?ShowLabels = ShowContoursLabels,
?LabelFont = ContoursLabelFont
)
let densityContourTrace =
Trace2D.initHistogram2DContour (
Trace2DStyle.Histogram2DContour(
XEncoded = xEncoded,
YEncoded = yEncoded,
Contours = contours,
Line = contourLines,
?NContours = NContours,
?ColorBar = ColorBar,
?ColorScale = ColorScale,
?ShowScale = ShowScale,
?HistNorm = HistNorm,
?Opacity = ContourOpacity
)
)
[
densityContourTrace :> Trace
pointTrace :> Trace
]
|> GenericChart.ofTraceObjects useDefaults