-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy path06_3_density-mapbox.fsx
77 lines (62 loc) · 2.21 KB
/
06_3_density-mapbox.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
(**
---
title: DensityMapbox charts
category: Mapbox map charts
categoryindex: 7
index: 4
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 12.0.3"
#r "nuget: DynamicObj"
#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# DensityMapbox charts
[](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[]({{root}}{{fsdocs-source-basename}}.fsx) 
[]({{root}}{{fsdocs-source-basename}}.ipynb)
*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]({{root}}/6_0_geo-vs-mapbox.html) and might need a Mapbox API token depending on the desired base map layer style.
*)
// 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.)
)
)
(*** condition: ipynb ***)
#if IPYNB
densityMapbox
#endif // IPYNB
(***hide***)
densityMapbox |> GenericChart.toChartHTML
(***include-it-raw***)