Skip to content

Commit 4b382e3

Browse files
committed
updates for new maps
1 parent 671c80d commit 4b382e3

File tree

2 files changed

+25
-44
lines changed

2 files changed

+25
-44
lines changed

doc/python/mapbox-density-heatmaps.md

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jupyter:
3030
order: 5
3131
page_type: u-guide
3232
permalink: python/density-heatmaps/
33-
thumbnail: thumbnail/mapbox-density.png
3433
redirect_from: python/mapbox-density-heatmaps/
34+
thumbnail: thumbnail/mapbox-density.png
3535
---
3636

3737
### Density map with `plotly.express`
@@ -51,28 +51,6 @@ fig = px.density_map(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=
5151
fig.show()
5252
```
5353

54-
<!-- #region -->
55-
### Stamen Terrain base map (Stadia Maps token needed): density heatmap with `plotly.express`
56-
57-
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`.
58-
59-
```python
60-
import plotly.express as px
61-
import pandas as pd
62-
63-
token = open(".mapbox_token").read() # you will need your own token
64-
65-
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
66-
67-
fig = px.density_map(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
68-
center=dict(lat=0, lon=180), zoom=0,
69-
map_style="stamen-terrain")
70-
fig.update_layout(mapbox_accesstoken=token)
71-
fig.show()
72-
```
73-
74-
<!-- #endregion -->
75-
7654
### Density map with `plotly.graph_objects`
7755

7856
If Plotly Express does not provide a good starting point, it is also possible to use [the more generic `go.Densitymap` class from `plotly.graph_objects`](/python/graph-objects/).
@@ -90,49 +68,52 @@ fig.show()
9068
```
9169

9270
<!-- #region -->
93-
### Stamen Terrain base map (Stadia Maps token needed): density heatmap with `plotly.graph_objects`
71+
### Mapbox Maps
9472

95-
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`.
73+
The earlier examples using `px.density_mapbox` and `go.Densitymap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. These trace types are now the recommended way to make tile-based density heatmaps. There are also traces that use Mapbox: `density_mapbox` and `go.Densitymapbox`.
74+
75+
To use these trace types, in some cases 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.
9676

77+
Here's one of the earlier examples rewritten to use `px.density_mapbox`.
9778

9879
```python
99-
import plotly.graph_objects as go
10080
import pandas as pd
81+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
10182

102-
token = open(".mapbox_token").read() # you will need your own token
103-
104-
quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
105-
106-
fig = go.Figure(go.Densitymap(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
107-
radius=10))
108-
fig.update_layout(map_style="stamen-terrain", map_center_lon=180, mapbox_accesstoken=token)
109-
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
83+
import plotly.express as px
84+
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
85+
center=dict(lat=0, lon=180), zoom=0,
86+
mapbox_style="open-street-map")
11087
fig.show()
11188
```
89+
11290
<!-- #endregion -->
11391

11492
<!-- #region -->
115-
### Mapbox Maps
116-
117-
The earlier examples using `px.density_mapbox` and `go.Densitymap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. These trace types are now the recommended way to make tile-based density heatmaps. There are also traces that use Mapbox: `density_mapbox` and `go.Densitymapbox`.
118-
119-
To use these trace types, in some cases 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.
93+
<!-- #region -->
94+
#### Stamen Terrain base map (Stadia Maps token needed): density heatmap with `plotly.express`
12095

121-
Here's one of the earlier examples rewritten to use `px.density_mapbox`.
96+
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`.
12297

12398
```python
99+
import plotly.express as px
124100
import pandas as pd
101+
102+
token = open(".mapbox_token").read() # you will need your own token
103+
125104
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
126105

127-
import plotly.express as px
128-
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
106+
fig = px.density_map(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
129107
center=dict(lat=0, lon=180), zoom=0,
130-
mapbox_style="open-street-map")
108+
map_style="stamen-terrain")
109+
fig.update_layout(mapbox_accesstoken=token)
131110
fig.show()
132111
```
133112

134113
<!-- #endregion -->
135114

115+
<!-- #endregion -->
116+
136117
#### Reference
137118

138119
See [function reference for `px.(density_map)`](https://plotly.com/python-api-reference/generated/plotly.express.density_mapbox) or https://plotly.com/python/reference/densitymap/ for available attribute options.

doc/python/mapbox-layers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fig.show()
204204
<!-- #region -->
205205
#### Stamen Watercolor using a Custom Style URL
206206

207-
Here's an example of using a custom style URL that points to the Stadia Maps service to use the `stamen_watercolor` base map.
207+
Here's an example of using a custom style URL that points to the [Stadia Maps](https://docs.stadiamaps.com/map-styles/stamen-watercolor) service to use the `stamen_watercolor` base map.
208208

209209
```python
210210
import pandas as pd

0 commit comments

Comments
 (0)