// can't yet format YamlFrontmatter (["title: Heatmaps"; "category: Simple Charts"; "categoryindex: 3"; "index: 8"], Some { StartLine = 2 StartColumn = 0 EndLine = 6 EndColumn = 8 }) to pynb markdown

In [ ]:
#r "nuget: Plotly.NET, 2.0.0-preview.16"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.16"


# Heatmaps¶

Summary: This example shows how to create heatmap charts in F#.

let's first create some data for the purpose of creating example charts:

In [3]:
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 2 dimensional data that represents the z dimension. the X and Y dimension sizes can be inferred from the z data:

In [4]:
// Generating the Heatmap with only z Data
let heat1 =
Chart.Heatmap(
matrix
)

In [ ]:
heat1

Out[ ]:

## Inverting the Y Axis¶

Per 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.

In [6]:
// Addning row/column names and inverting the Y axis:
let heat2 =
Chart.Heatmap(
matrix,
colnames,
rownames,
ReverseYAxis = true
)

In [ ]:
heat2

Out[ ]:

## 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:

In [8]:
let heat3 =
Chart.Heatmap(
matrix,
ColorScale = StyleParam.Colorscale.Viridis
)
|> Chart.withColorBarStyle(
Title.init("Im the ColorBar")
)

In [ ]:
heat3

Out[ ]:

## Annotated Heatmaps¶

use Chart.AnnotatedHeatmap to add an annotation text to each z value:

In [10]:
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
)

In [ ]:
heat4

Out[ ]: