-
Notifications
You must be signed in to change notification settings - Fork 85
/
05_0_geo-vs-mapbox.fsx
133 lines (101 loc) · 4.63 KB
/
05_0_geo-vs-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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
(**
---
title: Geo vs. Mapbox
category: Geo map charts
categoryindex: 6
index: 1
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 2.0.0"
#r "../src/Plotly.NET/bin/Release/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
(**
# Mapbox Maps vs Geo Maps
[![Binder]({{root}}img/badge-binder.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb) 
[![Script]({{root}}img/badge-script.svg)]({{root}}{{fsdocs-source-basename}}.fsx) 
[![Notebook]({{root}}img/badge-notebook.svg)]({{root}}{{fsdocs-source-basename}}.ipynb)
*Summary:* This introduction shows the differences between Geo and Mapbox based geographical charts.
Plotly and therefore Plotly.NET supports two different kinds of maps:
- **Mapbox maps** are tile-based maps. If your figure is created with a `Chart.*Mapbox` function or otherwise contains one or more traces of type `scattermapbox`,
`choroplethmapbox` or `densitymapbox`, the layout.mapbox object in your figure contains configuration information for the map itself.
- **Geo maps** are outline-based maps. If your figure is created with a `Chart.ScatterGeo, `Chart.PointGeo`, `Chart.LineGeo` or `Chart.Choropleth` function or
otherwise contains one or more traces of type `scattergeo` or `choropleth`, the layout.geo object in your figure contains configuration information for the map itself.
_This page documents Geo outline-based maps, and the [Mapbox Layers documentation]({{root}}/06_0_geo-vs-mapbox.html) describes how to configure Mapbox tile-based maps._
## Physical Base Maps
Plotly Geo maps have a built-in base map layer composed of "physical" and "cultural" (i.e. administrative border) data from the Natural Earth Dataset.
Various lines and area fills can be shown or hidden, and their color and line-widths specified.
In the default plotly template, a map frame and physical features such as a coastal outline and filled land areas are shown, at a small-scale 1:110m resolution:
*)
open Plotly.NET
let baseMapOnly =
Chart.PointGeo(locations = []) // deliberately empty chart to show the base map only
|> Chart.withMarginSize(0,0,0,0)
(*** condition: ipynb ***)
#if IPYNB
baseLayerOnly
#endif // IPYNB
(***hide***)
baseMapOnly |> GenericChart.toChartHTML
(***include-it-raw***)
(**
To control the features of the map, a `Geo` object is used that can be associtaed with a given chart using the `Chart.WithGeo` function.
Here is a map with all physical features enabled and styled, at a larger-scale 1:50m resolution:
*)
open Plotly.NET.LayoutObjects
let myGeo =
Geo.init(
Resolution=StyleParam.GeoResolution.R50,
ShowCoastLines=true,
CoastLineColor=Color.fromString "RebeccaPurple",
ShowLand=true,
LandColor=Color.fromString "LightGreen",
ShowOcean=true,
OceanColor=Color.fromString "LightBlue",
ShowLakes=true,
LakeColor=Color.fromString "Blue",
ShowRivers=true,
RiverColor=Color.fromString "Blue"
)
let moreFeaturesBaseMap =
Chart.PointGeo(locations = [])
|> Chart.withGeo myGeo
|> Chart.withMarginSize(0,0,0,0)
(*** condition: ipynb ***)
#if IPYNB
moreFeaturesBaseMap
#endif // IPYNB
(***hide***)
moreFeaturesBaseMap |> GenericChart.toChartHTML
(***include-it-raw***)
(**
## Cultural Base Maps
In addition to physical base map features, a "cultural" base map is included which is composed of country borders and selected sub-country borders such as states.
_Note and disclaimer: cultural features are by definition subject to change, debate and dispute. Plotly includes data from Natural Earth "as-is" and defers to the Natural Earth policy regarding disputed borders which read:_
> Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground.
Here is a map with only cultural features enabled and styled, at a 1:50m resolution, which includes only country boundaries. See below for country sub-unit cultural base map features:
*)
let countryGeo =
Geo.init(
Visible=false,
Resolution=StyleParam.GeoResolution.R50,
ShowCountries=true,
CountryColor=Color.fromString "RebeccaPurple"
)
let countryBaseMap =
Chart.PointGeo(locations = [])
|> Chart.withGeo countryGeo
|> Chart.withMarginSize(0,0,0,0)
(*** condition: ipynb ***)
#if IPYNB
countryBaseMap
#endif // IPYNB
(***hide***)
countryBaseMap |> GenericChart.toChartHTML
(***include-it-raw***)