// can't yet format YamlFrontmatter (["title: DensityMapbox charts"; "category: Mapbox map charts"; "categoryindex: 7"; "index: 4"], 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"

DensityMapbox charts

BinderScriptNotebook

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

Chart.DensityMapbox draws a bivariate kernel density estimation with a Gaussian kernel from lon and lat coordinates and optional z values using a colorscale. This Chart uses Mapbox layers and might need a Mapbox API token depending on the desired base map layer style.

In [3]:
// we are using the awesome FSharp.Data project here to perform a http request,
// and the awesome Deedle library to read the data as a data frame
#r "nuget: FSharp.Data"
#r "nuget: Deedle"

open FSharp.Data
open Deedle

let dataDensityMapbox = 
    Http.RequestString "https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv"
    |> fun d -> Frame.ReadCsvString(d,true,separators=",")

let lon = dataDensityMapbox.["Longitude"] |> Series.values
let lat= dataDensityMapbox.["Latitude"] |> Series.values
let magnitudes = dataDensityMapbox.["Magnitude"] |> Series.values

open Plotly.NET
open Plotly.NET.LayoutObjects

let densityMapbox = 
    Chart.DensityMapbox(
        lon,
        lat,
        Z = magnitudes,
        Radius=8,
        ColorScale=StyleParam.Colorscale.Viridis
    )
    |> Chart.withMapbox(
        Mapbox.init(
            Style = StyleParam.MapboxStyle.StamenTerrain,
            Center = (60.,30.)
        )
    )
In [ ]:
densityMapbox
Out[ ]: