Mapbox Density Heatmap in F#

How to make a Mapbox Density Heatmap in F# with Plotly.

In [1]:
#r "nuget: Plotly.NET,2.0.0-preview.8"
#r "nuget: Plotly.NET.Interactive,2.0.0-preview.8"
#r "nuget: FSharp.Data"
Installed Packages
  • FSharp.Data, 4.2.4
  • Plotly.NET, 2.0.0-preview.8
  • Plotly.NET.Interactive, 2.0.0-preview.8

Loading extensions from Plotly.NET.Interactive.dll

Added Kernel Extension including formatters for Plotly.NET charts.

Mapbox Access Token and Base Map Configuration

To plot on Mapbox maps with Plotly you may need a Mapbox account and a public Mapbox Access Token.

Stamen Terrain base map (no token needed): density mapbox with Plotly.NET

In [2]:
open FSharp.Data
open Plotly.NET
open Plotly.NET.LayoutObjects

let data = CsvFile.Load("")

let latitudes = data.Rows |> (fun row -> row.GetColumn("Latitude"))
let longitudes = data.Rows |> (fun row -> row.GetColumn("Longitude"))
let magnitudes = data.Rows |> (fun row -> row.GetColumn("Magnitude"))

let lonlat = longitudes latitudes

|> Chart.withMapbox(Mapbox.init(Style=StyleParam.MapboxStyle.StamenTerrain))
|> Chart.withMarginSize (Left = 0, Right = 0, Top = 0, Bottom = 0)