You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: How to make Mapbox maps in Python with various base layers, with
26
-
or without needing a Mapbox Access token.
25
+
description: How to make tile-based maps in Python with various base layers.
27
26
display_as: maps
28
27
language: python
29
28
layout: base
30
-
name: Mapbox Map Layers
29
+
name: Tile Map Layers
31
30
order: 8
32
31
page_type: u-guide
33
-
permalink: python/mapbox-layers/
32
+
permalink: /python/tile-map-layers/
33
+
redirect_from: /python/mapbox-layers/
34
34
thumbnail: thumbnail/mapbox-layers.png
35
35
---
36
36
37
37
<!-- #region -->
38
38
39
-
### Mapbox Maps vs Geo Maps
39
+
##Tile Maps vs Outline Maps
40
40
41
41
Plotly supports two different kinds of maps:
42
42
43
-
1.**Mapbox maps** are [tile-based maps](https://en.wikipedia.org/wiki/Tiled_web_map). If your figure is created with a `px.scatter_mapbox`, `px.line_mapbox`, `px.choropleth_mapbox` or `px.density_mapbox` function or otherwise contains one or more traces of type `go.Scattermapbox`, `go.Choroplethmapbox` or `go.Densitymapbox`, the `layout.mapbox` object in your figure contains configuration information for the map itself.
44
-
2.**Geo maps** are outline-based maps. If your figure is created with a `px.scatter_geo`, `px.line_geo` or `px.choropleth` function or otherwise contains one or more traces of type `go.Scattergeo` or `go.Choropleth`, the `layout.geo` object in your figure contains configuration information for the map itself.
This page documents Mapbox tile-based maps, and the [Geo map documentation](/python/map-configuration/) describes how to configure outline-based maps.
45
+
If your figure is created with a `px.scatter_map`, `px_scatter_mapbox`, `px.line_map`, `px.line_mapbox`, `px.choropleth_map`, `px.choropleth_mapbox`, `px.density_map`, or `px.density_mapbox` function or otherwise contains one or more traces of type `go.Scattermap`, `go.Scattermapbox`,`go.Choroplethmap`, `go.Choroplethmapbox`, `go.Densitymap`, or `go.Densitymapbox` the `layout.map` or `layout.mapbox` object in your figure contains configuration information for the map itself.
47
46
48
-
#### How Layers Work in Mapbox Tile Maps
47
+
-**Outline-based maps**
49
48
50
-
Mapbox tile maps are composed of various layers, of three different types:
49
+
Geo maps are outline-based maps. If your figure is created with a `px.scatter_geo`, `px.line_geo` or `px.choropleth` function or otherwise contains one or more traces of type `go.Scattergeo` or `go.Choropleth`, the `layout.geo` object in your figure contains configuration information for the map itself.
51
50
52
-
1.`layout.mapbox.style` defines is the lowest layers, also known as your "base map"
53
-
2. The various traces in `data` are by default rendered above the base map (although this can be controlled via the `below` attribute).
54
-
3.`layout.mapbox.layers` is an array that defines more layers that are by default rendered above the traces in `data` (although this can also be controlled via the `below` attribute).
51
+
> This page documents tile-based maps, and the [Geo map documentation](/python/map-configuration/) describes how to configure outline-based maps.
55
52
56
-
#### Mapbox Access Tokens and When You Need Them
53
+
##Tile Map Renderers
57
54
58
-
The word "mapbox" in the trace names and `layout.mapbox` refers to the Mapbox GL JS open-source library, which is integrated into Plotly.py.
55
+
Tile-based traces in Plotly use Maplibre or Mapbox.
59
56
60
-
If your basemap in `layout.mapbox.style` uses data from the Mapbox _service_, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token. This token should be provided in `layout.mapbox.access_token` (or, if using Plotly Express, via the `px.set_mapbox_access_token()` configuration function).
57
+
Maplibre-based traces (new in 5.24) are ones generated in Plotly Express using `px.scatter_map`, `px.line_map`, `px.choropleth_map`, `px.density_map`, or Graph Objects using `go.Scattermap`, `go.Choroplethmap`, or `go.Densitymap`.
61
58
62
-
If you basemap in `layout.mapbox.style` uses maps from the [Stadia Maps service](https://www.stadiamaps.com) (see below for details), you'll need to register for a Stadia Maps account and token.
59
+
Mapbox-based traces are suffixed with `mapbox`, for example `go.Scattermapbox`. These are deprecated as of version 5.24 and we recommend using the Maplibre-based traces.
63
60
61
+
### Maplibre
64
62
65
-
#### Base Maps in `layout.mapbox.style`
63
+
*New in 5.24*
66
64
67
-
The accepted values for `layout.mapbox.style` are one of:
65
+
Maplibre-based tile maps have three different types of layers:
68
66
69
-
-`"white-bg"` yields an empty white canvas which results in no external HTTP requests
70
-
-`"open-street-map"`, `"carto-positron"`, and `"carto-darkmatter"` yield maps composed of _raster_ tiles from various public tile servers which do not require signups or access tokens.
71
-
-`"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yield maps composed of _vector_ tiles from the Mapbox service, and _do_ require a Mapbox Access Token or an on-premise Mapbox installation.
72
-
-`"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yield maps composed of _raster_ tiles from the [Stadia Maps service](https://www.stadiamaps.com), and require a Stadia Maps account and token.
73
-
- A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation.
74
-
- A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/
67
+
-`layout.map.style` defines the lowest layers of the map, also known as the "base map".
68
+
- The various traces in `data` are by default rendered above the base map (although this can be controlled via the `below` attribute).
69
+
-`layout.map.layers` is an array that defines more layers that are by default rendered above the traces in `data` (although this can also be controlled via the `below` attribute.
75
70
76
-
#### OpenStreetMap tiles: no token needed
77
71
78
-
Here is a simple map rendered with OpenStreetMaps tiles, without needing a Mapbox Access Token:
72
+
#### Base Maps in `layout.map.style`.
73
+
74
+
The accepted values for `layout.map.style` are one of:
75
+
76
+
- "basic"
77
+
- "carto-darkmatter"
78
+
- "carto-darkmatter-nolabels"
79
+
- "carto-positron"
80
+
- "carto-positron-nolabels"
81
+
- "carto-voyager"
82
+
- "carto-voyager-nolabels"
83
+
- "dark"
84
+
- "light"
85
+
- "open-street-map"
86
+
- "outdoors"
87
+
- "satellite"
88
+
- "satellite-streets"
89
+
- "streets"
90
+
- "white-bg" - an empty white canvas which results in no external HTTP requests
91
+
92
+
- A custom style URL. For example: https://tiles.stadiamaps.com/styles/stamen_watercolor.json?api_key=YOUR-API-KEY
93
+
94
+
- A Map Style object as defined at https://maplibre.org/maplibre-style-spec/
79
95
96
+
97
+
#### OpenStreetMap tiles
98
+
99
+
Here is a simple map rendered with OpenStreetMaps tiles.
#### Using `layout.map.layers` to Specify a Base Map
95
116
96
-
#### Using `layout.mapbox.layers` to Specify a Base Map
97
-
98
-
If you have access to your own private tile servers, or wish to use a tile server not included in the list above, the recommended approach is to set `layout.mapbox.style` to `"white-bg"` and to use `layout.mapbox.layers` with `below` to specify a custom base map.
117
+
If you have access to your own private tile servers, or wish to use a tile server not included in the list above, the recommended approach is to set `layout.map.style` to `"white-bg"` and to use `layout.map.layers` with `below` to specify a custom base map.
99
118
100
119
> If you omit the `below` attribute when using this approach, your data will likely be hidden by fully-opaque raster tiles!
101
120
102
121
#### Base Tiles from the USGS: no token needed
103
122
104
-
Here is an example of a map which uses a public USGS imagery map, specified in `layout.mapbox.layers`, and which is rendered _below_ the `data` layer.
105
-
123
+
Here is an example of a map which uses a public USGS imagery map, specified in `layout.map.layers`, and which is rendered _below_ the `data` layer.
#### Base Tiles from the USGS, radar overlay from Environment Canada: no token needed
150
+
#### Base Tiles from the USGS, radar overlay from Environment Canada
133
151
134
-
Here is the same example, with in addition, a WMS layer from Environment Canada which displays near-real-time radar imagery in partly-transparent raster tiles, rendered above the `go.Scattermapbox` trace, as is the default:
152
+
Here is the same example, with in addition, a WMS layer from Environment Canada which displays near-real-time radar imagery in partly-transparent raster tiles, rendered above the `go.Scattermap` trace, as is the default:
Mapbox tile maps are composed of various layers, of three different types:
210
+
211
+
1.`layout.mapbox.style` defines is the lowest layers, also known as your "base map"
212
+
2. The various traces in `data` are by default rendered above the base map (although this can be controlled via the `below` attribute).
213
+
3.`layout.mapbox.layers` is an array that defines more layers that are by default rendered above the traces in `data` (although this can also be controlled via the `below` attribute).
214
+
215
+
#### Mapbox Access Tokens and When You Need Them
216
+
217
+
The word "mapbox" in the trace names and `layout.mapbox` refers to the Mapbox GL JS open-source library, which is integrated into Plotly.py.
218
+
219
+
If your basemap in `layout.mapbox.style` uses data from the Mapbox _service_, then you will need to register for a free account at https://mapbox.com/ and obtain a Mapbox Access token. This token should be provided in `layout.mapbox.access_token` (or, if using Plotly Express, via the `px.set_mapbox_access_token()` configuration function).
220
+
221
+
If you basemap in `layout.mapbox.style` uses maps from the [Stadia Maps service](https://www.stadiamaps.com) (see below for details), you'll need to register for a Stadia Maps account and token.
222
+
223
+
224
+
#### Base Maps in `layout.mapbox.style`
225
+
226
+
The accepted values for `layout.mapbox.style` are one of:
227
+
228
+
-`"white-bg"` yields an empty white canvas which results in no external HTTP requests
229
+
-`"open-street-map"`, `"carto-positron"`, and `"carto-darkmatter"` yield maps composed of _raster_ tiles from various public tile servers which do not require signups or access tokens.
230
+
-`"basic"`, `"streets"`, `"outdoors"`, `"light"`, `"dark"`, `"satellite"`, or `"satellite-streets"` yield maps composed of _vector_ tiles from the Mapbox service, and _do_ require a Mapbox Access Token or an on-premise Mapbox installation.
231
+
-`"stamen-terrain"`, `"stamen-toner"` or `"stamen-watercolor"` yield maps composed of _raster_ tiles from the [Stadia Maps service](https://www.stadiamaps.com), and require a Stadia Maps account and token.
232
+
- A Mapbox service style URL, which requires a Mapbox Access Token or an on-premise Mapbox installation.
233
+
- A Mapbox Style object as defined at https://docs.mapbox.com/mapbox-gl-js/style-spec/
234
+
235
+
#### OpenStreetMap tiles: no token needed
236
+
237
+
Here is a simple map rendered with OpenStreetMaps tiles, without needing a Mapbox Access Token:
238
+
<!-- #endregion -->
173
239
174
240
```python
175
-
token =open(".mapbox_token").read() # you will need your own token
#### Using `layout.mapbox.layers` to Specify a Base Map
254
+
255
+
If you have access to your own private tile servers, or wish to use a tile server not included in the list above, the recommended approach is to set `layout.mapbox.style` to `"white-bg"` and to use `layout.mapbox.layers` with `below` to specify a custom base map.
256
+
257
+
> If you omit the `below` attribute when using this approach, your data will likely be hidden by fully-opaque raster tiles!
258
+
259
+
#### Base Tiles from the USGS: no token needed
176
260
261
+
Here is an example of a map which uses a public USGS imagery map, specified in `layout.mapbox.layers`, and which is rendered _below_ the `data` layer.
See https://plotly.com/python/reference/layout/mapbox/ for more information and options!
339
+
See https://plotly.com/python/reference/layout/map/ for more information and options on Maplibre-based tile maps and https://plotly.com/python/reference/layout/mapbox/ for Mapbox-based tile maps.
0 commit comments