Heatmaps

BinderScriptNotebook

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

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.)
    )
namespace Plotly
namespace Plotly.NET
val matrix : float list list
val rownames : string list
val colnames : string list
val colorscaleValue : StyleParam.Colorscale
module StyleParam

from Plotly.NET
type Colorscale =
  | Custom of seq<float * string>
  | RdBu
  | Earth
  | Blackbody
  | YIOrRd
  | YIGnBu
  | Bluered
  | Portland
  | Electric
  | Jet
  ...
    static member convert : (Colorscale -> obj)
union case StyleParam.Colorscale.Custom: seq<float * string> -> StyleParam.Colorscale
val heat1 : GenericChart.GenericChart
type Chart =
  static member Area : x:seq<#IConvertible> * y:seq<#IConvertible> * ?Name:string * ?ShowMarkers:bool * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Dash:DrawingStyle * ?Width:float -> GenericChart + 1 overload
  static member Bar : keys:seq<#IConvertible> * values:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:string * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart + 1 overload
  static member BoxPlot : ?x:'a0 * ?y:'a1 * ?Name:string * ?Showlegend:bool * ?Color:string * ?Fillcolor:'a2 * ?Opacity:float * ?Whiskerwidth:'a3 * ?Boxpoints:Boxpoints * ?Boxmean:BoxMean * ?Jitter:'a4 * ?Pointpos:'a5 * ?Orientation:Orientation * ?Marker:Marker * ?Line:Line * ?Alignmentgroup:'a6 * ?Offsetgroup:'a7 * ?Notched:bool * ?NotchWidth:float * ?QuartileMethod:QuartileMethod -> GenericChart + 1 overload
  static member Bubble : x:seq<#IConvertible> * y:seq<#IConvertible> * sizes:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?MarkerSymbol:Symbol * ?Color:string * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?StackGroup:string * ?Orientation:Orientation * ?GroupNorm:GroupNorm * ?UseWebGL:bool -> GenericChart + 1 overload
  static member Candlestick : open:seq<#IConvertible> * high:seq<#IConvertible> * low:seq<#IConvertible> * close:seq<#IConvertible> * x:seq<#IConvertible> * ?Increasing:Line * ?Decreasing:Line * ?WhiskerWidth:float * ?Line:Line * ?XCalendar:Calendar -> GenericChart + 1 overload
  static member ChoroplethMap : locations:seq<string> * z:seq<#IConvertible> * ?Text:seq<#IConvertible> * ?Locationmode:LocationFormat * ?Autocolorscale:bool * ?Colorscale:Colorscale * ?Colorbar:'a2 * ?Marker:Marker * ?Zmin:'a3 * ?Zmax:'a4 -> GenericChart
  static member Column : keys:seq<#IConvertible> * values:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Color:string * ?Opacity:float * ?Labels:seq<#IConvertible> * ?TextPosition:TextPosition * ?TextFont:Font * ?Marker:Marker -> GenericChart + 1 overload
  static member Contour : data:seq<#seq<'a1>> * ?X:seq<#IConvertible> * ?Y:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'a4 * ?zSmooth:SmoothAlg * ?Colorbar:'a5 -> GenericChart (requires 'a1 :> IConvertible)
  static member Doughnut : values:seq<#IConvertible> * ?Labels:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Colors:seq<string> * ?Hole:float * ?TextPosition:TextPosition * ?TextFont:Font * ?Hoverinfo:string * ?Textinfo:'a2 * ?Opacity:float -> GenericChart + 1 overload
  static member Heatmap : data:seq<#seq<'b>> * ?ColNames:seq<#IConvertible> * ?RowNames:seq<#IConvertible> * ?Name:string * ?Showlegend:bool * ?Opacity:float * ?Colorscale:Colorscale * ?Showscale:'e * ?Xgap:'f * ?Ygap:'g * ?zSmooth:SmoothAlg * ?Colorbar:'h * ?UseWebGL:bool -> GenericChart (requires 'b :> IConvertible)
  ...
static member Chart.Heatmap : data:seq<#seq<'b>> * ?ColNames:seq<#System.IConvertible> * ?RowNames:seq<#System.IConvertible> * ?Name:string * ?Showlegend:bool * ?Opacity:float * ?Colorscale:StyleParam.Colorscale * ?Showscale:'e * ?Xgap:'f * ?Ygap:'g * ?zSmooth:StyleParam.SmoothAlg * ?Colorbar:'h * ?UseWebGL:bool -> GenericChart.GenericChart (requires 'b :> System.IConvertible)
static member Chart.withSize : width:float * height:float -> (GenericChart.GenericChart -> GenericChart.GenericChart)
static member Chart.withMarginSize : ?Left:'a * ?Right:'b * ?Top:'c * ?Bottom:'d * ?Pad:'e * ?Autoexpand:'f -> (GenericChart.GenericChart -> GenericChart.GenericChart)
module GenericChart

from Plotly.NET
val toChartHTML : gChart:GenericChart.GenericChart -> string
val heat2 : GenericChart.GenericChart
static member Chart.withColorBarStyle : title:string * ?TitleSide:StyleParam.Side * ?TitleFont:Font * ?Length:float * ?OutlineColor:string * ?BorderColor:string * ?BGColor:string -> (GenericChart.GenericChart -> GenericChart.GenericChart)
type Side =
  | Top
  | Bottom
  | Left
  | Right
    static member convert : (Side -> obj)
    static member toString : (Side -> string)
union case StyleParam.Side.Right: StyleParam.Side
Multiple items
type Font =
  inherit DynamicObj
  new : unit -> Font
  static member init : ?Family:FontFamily * ?Size:float * ?Color:string -> Font
  static member style : ?Family:FontFamily * ?Size:float * ?Color:string -> (Font -> Font)

--------------------
new : unit -> Font
static member Font.init : ?Family:StyleParam.FontFamily * ?Size:float * ?Color:string -> Font