-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathheatmaps.fsx
132 lines (97 loc) · 3.3 KB
/
heatmaps.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
(**
---
title: Heatmaps
category: Simple Charts
categoryindex: 3
index: 8
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 2.0.0"
#r "nuget: Giraffe.ViewEngine.StrongName, 2.0.0-alpha1"
#r "../../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll"
Plotly.NET.Defaults.DefaultDisplayOptions <-
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# Heatmaps
[](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb) 
[]({{root}}{{fsdocs-source-basename}}.ipynb)
*Summary:* This example shows how to create heatmap charts in F#.
Let's first create some data for the purpose of creating example charts:
*)
open Plotly.NET
let matrix =
[ [ 1.; 1.5; 0.7; 2.7 ]; [ 2.; 0.5; 1.2; 1.4 ]; [ 0.1; 2.6; 2.4; 3.0 ] ]
let rownames = [ "p3"; "p2"; "p1" ]
let colnames = [ "Tp0"; "Tp30"; "Tp60"; "Tp160" ]
(**
A heatmap chart can be created using the `Chart.Heatmap` functions.
When creating heatmap charts, it is usually desirable to provide the values in matrix form, rownames and colnames.
A heatmap needs at least two-dimensional data that represents the z dimension. The X and Y dimension sizes can be inferred from the z data:
*)
// Generating the Heatmap with only z Data
let heat1 = Chart.Heatmap(zData = matrix)
(*** condition: ipynb ***)
#if IPYNB
heat1
#endif // IPYNB
(***hide***)
heat1 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## Inverting the Y Axis
By default, the y axis starts at the origin of the X/Y plane.
If it is however desired to represent a 2D matrix exactly how it is notated, invert the YAxis by setting `ReverseYAxis`.
*)
// Addning row/column names and inverting the Y axis:
let heat2 =
Chart.Heatmap(zData = matrix, colNames = colnames, rowNames = rownames, ReverseYAxis = true)
(*** condition: ipynb ***)
#if IPYNB
heat2
#endif // IPYNB
(***hide***)
heat2 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## Styling Colorbars and using custom color scales
The colorscale can be set via the `ColorScale` argument.
All charts that contain colorbars can be styled by the `Chart.withColorBarStyle` function.
Here is an example that adds a title to the colorbar:
*)
let heat3 =
Chart.Heatmap(zData = matrix, ColorScale = StyleParam.Colorscale.Viridis)
|> Chart.withColorBarStyle (TitleText = "Im the ColorBar")
(*** condition: ipynb ***)
#if IPYNB
heat3
#endif // IPYNB
(***hide***)
heat3 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## Annotated Heatmaps
Use `Chart.AnnotatedHeatmap` to add an annotation text to each z value:
*)
let heat4 =
Chart.AnnotatedHeatmap(
zData = [ [ 1..5 ]; [ 6..10 ]; [ 11..15 ] ],
annotationText = [ [ "1,1"; "1,2"; "1,3" ]; [ "2,1"; "2,2"; "2,3" ]; [ "3,1"; "3,2"; "3,3" ] ],
X = [ "C1"; "C2"; "C3" ],
Y = [ "R1"; "R2"; "R3" ],
ReverseYAxis = true
)
(*** condition: ipynb ***)
#if IPYNB
heat4
#endif // IPYNB
(***hide***)
heat4 |> GenericChart.toChartHTML
(***include-it-raw***)