Skip to content

Commit 4a70af6

Browse files
committed
update density heatmaps + fix typo
1 parent 9dc8202 commit 4a70af6

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

doc/python/filled-area-on-mapbox.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ fig.show()
137137
<!-- #region -->
138138
### Mapbox Maps
139139

140-
The earlier examples using `go.Scattermap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. This trace types is now the recommended way to draw filled areas on tile-based maps. There is also a trace that uses Mapbox, called `go.Scattermapbox`.
140+
The earlier examples using `go.Scattermap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. This trace type is now the recommended way to draw filled areas on tile-based maps. There is also a trace that uses Mapbox, called `go.Scattermapbox`.
141141

142142
To use the `Scattermapbox` trace type, 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.
143143

doc/python/mapbox-density-heatmaps.md

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.3'
9-
jupytext_version: 1.14.6
9+
jupytext_version: 1.16.3
1010
kernelspec:
1111
display_name: Python 3 (ipykernel)
1212
language: python
@@ -20,42 +20,39 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.10.11
23+
version: 3.10.0
2424
plotly:
25-
description: How to make a Mapbox Density Heatmap in Python with Plotly.
25+
description: How to make a density heatmap in Python with Plotly.
2626
display_as: maps
2727
language: python
2828
layout: base
29-
name: Mapbox Density Heatmap
29+
name: Density Heatmap
3030
order: 5
3131
page_type: u-guide
32-
permalink: python/mapbox-density-heatmaps/
32+
permalink: python/density-heatmaps/
3333
thumbnail: thumbnail/mapbox-density.png
34+
redirect_from: python/mapbox-density-heatmaps/
3435
---
3536

36-
#### Mapbox Access Token
37-
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.
39-
40-
### OpenStreetMap base map (no token needed): density mapbox with `plotly.express`
37+
### Density map with `plotly.express`
4138

4239
[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/).
4340

44-
With `px.density_mapbox`, each row of the DataFrame is represented as a point smoothed with a given radius of influence.
41+
With `px.density_map`, each row of the DataFrame is represented as a point smoothed with a given radius of influence.
4542

4643
```python
4744
import pandas as pd
4845
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
4946

5047
import plotly.express as px
51-
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
48+
fig = px.density_map(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
5249
center=dict(lat=0, lon=180), zoom=0,
53-
mapbox_style="open-street-map")
50+
map_style="open-street-map")
5451
fig.show()
5552
```
5653

5754
<!-- #region -->
58-
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.express`
55+
### Stamen Terrain base map (Stadia Maps token needed): density heatmap with `plotly.express`
5956

6057
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`.
6158

@@ -67,33 +64,33 @@ token = open(".mapbox_token").read() # you will need your own token
6764

6865
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
6966

70-
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
67+
fig = px.density_map(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
7168
center=dict(lat=0, lon=180), zoom=0,
72-
mapbox_style="stamen-terrain")
69+
map_style="stamen-terrain")
7370
fig.update_layout(mapbox_accesstoken=token)
7471
fig.show()
7572
```
7673

7774
<!-- #endregion -->
7875

79-
### OpenStreetMap base map (no token needed): density mapbox with `plotly.graph_objects`
76+
### Density map with `plotly.graph_objects`
8077

81-
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/).
78+
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/).
8279

8380
```python
8481
import pandas as pd
8582
quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
8683

8784
import plotly.graph_objects as go
88-
fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
85+
fig = go.Figure(go.Densitymap(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
8986
radius=10))
90-
fig.update_layout(mapbox_style="open-street-map", mapbox_center_lon=180)
87+
fig.update_layout(map_style="open-street-map", map_center_lon=180)
9188
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
9289
fig.show()
9390
```
9491

9592
<!-- #region -->
96-
### Stamen Terrain base map (Stadia Maps token needed): density mapbox with `plotly.graph_objects`
93+
### Stamen Terrain base map (Stadia Maps token needed): density heatmap with `plotly.graph_objects`
9794

9895
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`.
9996

@@ -106,14 +103,38 @@ token = open(".mapbox_token").read() # you will need your own token
106103

107104
quakes = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
108105

109-
fig = go.Figure(go.Densitymapbox(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
106+
fig = go.Figure(go.Densitymap(lat=quakes.Latitude, lon=quakes.Longitude, z=quakes.Magnitude,
110107
radius=10))
111-
fig.update_layout(mapbox_style="stamen-terrain", mapbox_center_lon=180, mapbox_accesstoken=token)
108+
fig.update_layout(map_style="stamen-terrain", map_center_lon=180, mapbox_accesstoken=token)
112109
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
113110
fig.show()
114111
```
115112
<!-- #endregion -->
116113

114+
<!-- #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.
120+
121+
Here's one of the earlier examples rewritten to use `px.density_mapbox`.
122+
123+
```python
124+
import pandas as pd
125+
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')
126+
127+
import plotly.express as px
128+
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
129+
center=dict(lat=0, lon=180), zoom=0,
130+
mapbox_style="open-street-map")
131+
fig.show()
132+
```
133+
134+
<!-- #endregion -->
135+
117136
#### Reference
118137

119-
See [function reference for `px.(density_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.density_mapbox) or https://plotly.com/python/reference/densitymapbox/ for more information about mapbox and their attribute options.
138+
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.
139+
140+
For Mapbox-based maps, see [function reference for `px.(density_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.density_mapbox) or https://plotly.com/python/reference/densitymapbox/.

0 commit comments

Comments
 (0)