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
Copy file name to clipboardExpand all lines: doc/python/mapbox-density-heatmaps.md
+31-13Lines changed: 31 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ jupyter:
5
5
text_representation:
6
6
extension: .md
7
7
format_name: markdown
8
-
format_version: '1.2'
9
-
jupytext_version: 1.3.0
8
+
format_version: '1.3'
9
+
jupytext_version: 1.15.1
10
10
kernelspec:
11
-
display_name: Python 3
11
+
display_name: Python 3 (ipykernel)
12
12
language: python
13
13
name: python3
14
14
language_info:
@@ -20,7 +20,7 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.3
23
+
version: 3.10.4
24
24
plotly:
25
25
description: How to make a Mapbox Density Heatmap in Python with Plotly.
26
26
display_as: maps
@@ -33,42 +33,60 @@ jupyter:
33
33
thumbnail: thumbnail/mapbox-density.png
34
34
---
35
35
36
-
#### Mapbox Access Token
37
-
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.
39
-
40
-
### Stamen Terrain base map (no token needed): density mapbox with `plotly.express`
36
+
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.express`
41
37
42
38
[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/).
43
39
44
40
With `px.density_mapbox`, each row of the DataFrame is represented as a point smoothed with a given radius of influence.
45
41
42
+
To use the mapbox_style "stamen-terrain", you'll need a [Stadia Maps](https://www.stadiamaps.com) token, which you can provide to the `mapbox_accesstoken` parameter on `fig.update_layout`.
43
+
44
+
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`.
45
+
46
+
<!-- #region -->
46
47
```python
48
+
import plotly.express as px
47
49
import pandas as pd
50
+
51
+
token =open(".mapbox_token").read() # you will need your own token
### Stamen Terrain base map (no token needed): density mapbox with `plotly.graph_objects`
65
+
66
+
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.graph_objects`
58
67
59
68
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/).
60
69
70
+
<!-- #region -->
61
71
```python
72
+
import plotly.graph_objects as go
62
73
import pandas as pd
74
+
75
+
token =open(".mapbox_token").read() # you will need your own token
0 commit comments