Skip to content

Commit be7b3c5

Browse files
committed
fix and add additional heatmap docs
1 parent 78cf1ba commit be7b3c5

File tree

1 file changed

+74
-15
lines changed

1 file changed

+74
-15
lines changed

docs/02_7_heatmaps.fsx

Lines changed: 74 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,20 @@ let matrix =
4343
let rownames = ["p3";"p2";"p1"]
4444
let colnames = ["Tp0";"Tp30";"Tp60";"Tp160"]
4545

46-
let colorscaleValue =
47-
StyleParam.Colorscale.Custom [(0.0,"#3D9970");(1.0,"#001f3f")]
46+
(**
47+
48+
A heatmap chart can be created using the `Chart.Heatmap` functions.
49+
50+
When creating heatmap charts, it is usually desirable to provide the values in matrix form, rownames and colnames.
51+
52+
A heatmap needs at least 2 dimensional data that represents the z dimension. the X and Y dimension sizes can be inferred from the z data:
53+
*)
4854

49-
// Generating the Heatmap
55+
// Generating the Heatmap with only z Data
5056
let heat1 =
5157
Chart.Heatmap(
52-
matrix,colnames,rownames,
53-
Colorscale=colorscaleValue,
54-
Showscale=true
58+
matrix
5559
)
56-
|> Chart.withSize(700.,500.)
57-
|> Chart.withMarginSize(Left=200.)
5860

5961
(*** condition: ipynb ***)
6062
#if IPYNB
@@ -66,28 +68,85 @@ heat1 |> GenericChart.toChartHTML
6668
(***include-it-raw***)
6769

6870
(**
69-
A heatmap chart can be created using the `Chart.HeatMap` functions.
70-
When creating heatmap charts, it is usually desirable to provide the values in matrix form, rownames and colnames.
71+
## Inverting the Y Axis
72+
73+
Per default, the y axis starts at the origin of the X/Y plane.
74+
If it is however desired to represent a 2D matrix exactly how it is notated, invert the YAxis by setting `ReverseYAxis`.
7175
*)
7276

77+
// Addning row/column names and inverting the Y axis:
78+
let heat2 =
79+
Chart.Heatmap(
80+
matrix,
81+
colnames,
82+
rownames,
83+
ReverseYAxis = true
84+
)
85+
86+
(*** condition: ipynb ***)
87+
#if IPYNB
88+
heat2
89+
#endif // IPYNB
90+
91+
(***hide***)
92+
heat2 |> GenericChart.toChartHTML
93+
(***include-it-raw***)
94+
7395
(**
74-
## Styling Colorbars
96+
## Styling Colorbars and using custom color scales
7597
98+
The colorscale can be set via the `ColorScale` argument.
7699
All charts that contain colorbars can be styled by the `Chart.withColorBarStyle` function.
77100
Here is an example that adds a title to the colorbar:
78101
*)
79102

80-
let heat2 =
81-
heat1
103+
let heat3 =
104+
Chart.Heatmap(
105+
matrix,
106+
ColorScale = StyleParam.Colorscale.Viridis
107+
)
82108
|> Chart.withColorBarStyle(
83109
Title.init("Im the ColorBar")
84110
)
85111

86112
(*** condition: ipynb ***)
87113
#if IPYNB
88-
heat2
114+
heat3
89115
#endif // IPYNB
90116

91117
(***hide***)
92-
heat2 |> GenericChart.toChartHTML
118+
heat3 |> GenericChart.toChartHTML
93119
(***include-it-raw***)
120+
121+
122+
(**
123+
## Annotated Heatmaps
124+
125+
use `Chart.AnnotatedHeatmap` to add an annotation text to each z value:
126+
*)
127+
128+
let heat4 =
129+
Chart.AnnotatedHeatmap(
130+
zData = [
131+
[1..5]
132+
[6..10]
133+
[11..15]
134+
],
135+
annotationText = [
136+
["1,1";"1,2";"1,3"]
137+
["2,1";"2,2";"2,3"]
138+
["3,1";"3,2";"3,3"]
139+
],
140+
X = ["C1";"C2";"C3"],
141+
Y = ["R1";"R2";"R3"],
142+
ReverseYAxis = true
143+
)
144+
145+
(*** condition: ipynb ***)
146+
#if IPYNB
147+
heat4
148+
#endif // IPYNB
149+
150+
(***hide***)
151+
heat4 |> GenericChart.toChartHTML
152+
(***include-it-raw***)

0 commit comments

Comments
 (0)