-
Notifications
You must be signed in to change notification settings - Fork 81
/
2_7_heatmaps.fsx
94 lines (73 loc) · 2.12 KB
/
2_7_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
(**
---
title: Heatmaps
category: Simple Charts
categoryindex: 3
index: 8
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#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
(**
# Heatmaps
[![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 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"]
let colorscaleValue =
StyleParam.Colorscale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
// Generating the Heatmap
let heat1 =
Chart.Heatmap(
matrix,colnames,rownames,
Colorscale=colorscaleValue,
Showscale=true
)
|> Chart.withSize(700.,500.)
|> Chart.withMarginSize(Left=200.)
(*** condition: ipynb ***)
#if IPYNB
heat1
#endif // IPYNB
(***hide***)
heat1 |> GenericChart.toChartHTML
(***include-it-raw***)
(**
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.
*)
(**
## Styling Colorbars
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 heat2 =
heat1
|> Chart.withColorBarStyle(
"Im the Colorbar",
TitleSide = StyleParam.Side.Right,
TitleFont = Font.init(Size=20.)
)
(*** condition: ipynb ***)
#if IPYNB
heat2
#endif // IPYNB
(***hide***)
heat2 |> GenericChart.toChartHTML
(***include-it-raw***)