Skip to content

Commit df37b81

Browse files
committed
update information on stadia maps
1 parent 7e4a258 commit df37b81

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

doc/python/mapbox-density-heatmaps.md

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ jupyter:
55
text_representation:
66
extension: .md
77
format_name: markdown
8-
format_version: '1.2'
9-
jupytext_version: 1.3.0
8+
format_version: '1.3'
9+
jupytext_version: 1.14.6
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.3
23+
version: 3.10.11
2424
plotly:
2525
description: How to make a Mapbox Density Heatmap in Python with Plotly.
2626
display_as: maps
@@ -35,9 +35,10 @@ jupyter:
3535

3636
#### Mapbox Access Token
3737

38-
To plot on Mapbox maps with Plotly you _may_ need a Mapbox account and a public [Mapbox Access Token](https://www.mapbox.com/studio). See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more information.
38+
To plot on Mapbox maps with Plotly, you may need a [Mapbox account and token](https://www.mapbox.com/studio) or a [Stadia Maps account and token](https://www.stadiamaps.com), depending on base map (`mapbox_style`) you use. On this page, we show how to use the "open-street-map" base map, which doesn't require a token, and a "stamen" base map, which requires a Stadia Maps token. See our [Mapbox Map Layers](/python/mapbox-layers/) documentation for more examples.
3939

40-
### Stamen Terrain base map (no token needed): density mapbox with `plotly.express`
40+
41+
### OpenStreetMap base map (no token needed): density mapbox with `plotly.express`
4142

4243
[Plotly Express](/python/plotly-express/) is the easy-to-use, high-level interface to Plotly, which [operates on a variety of types of data](/python/px-arguments/) and produces [easy-to-style figures](/python/styling-plotly-express/).
4344

@@ -48,13 +49,35 @@ import pandas as pd
4849
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
4950

5051
import plotly.express as px
52+
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
53+
center=dict(lat=0, lon=180), zoom=0,
54+
mapbox_style="open-street-map")
55+
fig.show()
56+
```
57+
58+
<!-- #region -->
59+
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.express`
60+
61+
Some base maps require a token. To use "stamen" base maps, you'll need a [Stadia Maps](https://www.stadiamaps.com) token, which you can provide to the `mapbox_accesstoken` parameter on `fig.update_layout`. Here, we have the token saved in a file called `.mapbox_token`, load it in to the variable `token`, and then pass it to `mapbox_accesstoken`.
62+
63+
```python
64+
import plotly.express as px
65+
import pandas as pd
66+
67+
token = open(".mapbox_token").read() # you will need your own token
68+
69+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
70+
5171
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
5272
center=dict(lat=0, lon=180), zoom=0,
5373
mapbox_style="stamen-terrain")
74+
fig.update_layout(mapbox_accesstoken=token)
5475
fig.show()
5576
```
5677

57-
### Stamen Terrain base map (no token needed): density mapbox with `plotly.graph_objects`
78+
<!-- #endregion -->
79+
80+
### OpenStreetMap base map (no token needed): density mapbox with `plotly.graph_objects`
5881

5982
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Densitymapbox` class from `plotly.graph_objects`](/python/graph-objects/).
6083

@@ -65,10 +88,32 @@ quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/e
6588
import plotly.graph_objects as go
6689
fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
6790
radius=10))
68-
fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180)
91+
fig.update_layout(mapbox_style="open-street-map", mapbox_center_lon=180)
92+
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
93+
fig.show()
94+
```
95+
96+
<!-- #region -->
97+
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.graph_objects`
98+
99+
Some base maps require a token. To use "stamen" base maps, you'll need a [Stadia Maps](https://www.stadiamaps.com) token, which you can provide to the `mapbox_accesstoken` parameter on `fig.update_layout`. Here, we have the token saved in a file called `.mapbox_token`, load it in to the variable `token`, and then pass it to `mapbox_accesstoken`.
100+
101+
102+
```python
103+
import plotly.graph_objects as go
104+
import pandas as pd
105+
106+
token = open(".mapbox_token").read() # you will need your own token
107+
108+
quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
109+
110+
fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
111+
radius=10))
112+
fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180, mapbox_accesstoken=token)
69113
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
70114
fig.show()
71115
```
116+
<!-- #endregion -->
72117

73118
#### Reference
74119

0 commit comments

Comments
 (0)