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/filled-area-on-mapbox.md
+51-28Lines changed: 51 additions & 28 deletions
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.1'
9
-
jupytext_version: 1.1.1
8
+
format_version: '1.3'
9
+
jupytext_version: 1.16.3
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,68 +20,63 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.6.8
23
+
version: 3.10.0
24
24
plotly:
25
-
description: How to make an area on Map in Python with Plotly.
25
+
description: How to make an area on tile-based maps in Python with Plotly.
26
26
display_as: maps
27
27
language: python
28
28
layout: base
29
29
name: Filled Area on Maps
30
30
order: 3
31
31
page_type: example_index
32
-
permalink: python/filled-area-on-mapbox/
32
+
permalink: python/filled-area-tile-maps/
33
+
redirect_from: python/filled-area-on-mapbox/
33
34
thumbnail: thumbnail/area.jpg
34
35
---
35
36
36
-
<!-- #region -->
37
-
38
-
### Mapbox Access Token and Base Map Configuration
39
-
40
-
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.
37
+
There are three different ways to show a filled area on a tile-based map:
41
38
42
-
There are three different ways to show a filled area in a Mapbox map:
39
+
- Using a [Scattermap](https://plotly.com/python/reference/scattermap/) trace and set `fill` attribute to 'toself'
40
+
- Using a map layout (i.e. by minimally using an empty [Scattermap](https://plotly.com/python/reference/scattermap/) trace) and adding a GeoJSON layer
41
+
- Using the [Choroplethmap](https://plotly.com/python/tile-county-choropleth/) trace type
43
42
44
-
1. Use a [Scattermapbox](https://plotly.com/python/reference/scattermapbox/) trace and set `fill` attribute to 'toself'
45
-
2. Use a Mapbox layout (i.e. by minimally using an empty [Scattermapbox](https://plotly.com/python/reference/scattermapbox/) trace) and add a GeoJSON layer
46
-
3. Use the [Choroplethmapbox](https://plotly.com/python/mapbox-county-choropleth/) trace type
47
-
<!-- #endregion -->
43
+
## Filled `Scattermap` Trace
48
44
49
-
### Filled `Scattermapbox` Trace
50
-
51
-
The following example uses `Scattermapbox` and sets `fill = 'toself'`
45
+
The following example uses Scattermap and sets fill = 'toself'
52
46
53
47
```python
54
48
import plotly.graph_objects as go
55
49
56
-
fig = go.Figure(go.Scattermapbox(
50
+
fig = go.Figure(go.Scattermap(
57
51
fill="toself",
58
52
lon= [-74, -70, -70, -74], lat= [47, 47, 45, 45],
59
53
marker= { 'size': 10, 'color': "orange" }))
60
54
61
55
fig.update_layout(
62
-
mapbox= {
56
+
map= {
63
57
'style': "open-street-map",
64
58
'center': {'lon': -73, 'lat': 46 },
65
59
'zoom': 5},
66
60
showlegend=False)
67
61
68
62
fig.show()
63
+
69
64
```
70
65
71
-
### Multiple Filled Areas with a `Scattermapbox` trace
66
+
### Multiple Filled Areas with a `Scattermap` trace
72
67
73
-
The following example shows how to use `None` in your data to draw multiple filled areas. Such gaps in trace data are unconnected by default, but this can be controlled via the [connectgaps](https://plotly.com/python/reference/scattermapbox/#scattermapbox-connectgaps) attribute.
68
+
The following example shows how to use `None` in your data to draw multiple filled areas. Such gaps in trace data are unconnected by default, but this can be controlled via the [connectgaps](https://plotly.com/python/reference/scattermap/#scattermap-connectgaps) attribute.
@@ -95,13 +90,13 @@ In this map we add a GeoJSON layer.
95
90
```python
96
91
import plotly.graph_objects as go
97
92
98
-
fig = go.Figure(go.Scattermapbox(
93
+
fig = go.Figure(go.Scattermap(
99
94
mode="markers",
100
95
lon= [-73.605], lat= [45.51],
101
96
marker= {'size': 20, 'color': ["cyan"]}))
102
97
103
98
fig.update_layout(
104
-
mapbox= {
99
+
map= {
105
100
'style': "open-street-map",
106
101
'center': { 'lon': -73.6, 'lat': 45.5},
107
102
'zoom': 12, 'layers': [{
@@ -139,6 +134,34 @@ fig.update_layout(
139
134
fig.show()
140
135
```
141
136
137
+
<!-- #region -->
138
+
### Mapbox Maps
139
+
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`.
141
+
142
+
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.
143
+
144
+
Here's one of the earlier examples rewritten to use `Scattermapbox`.
145
+
146
+
```python
147
+
import plotly.graph_objects as go
148
+
149
+
fig = go.Figure(go.Scattermapbox(
150
+
fill="toself",
151
+
lon= [-74, -70, -70, -74], lat= [47, 47, 45, 45],
152
+
marker= { 'size': 10, 'color': "orange" }))
153
+
154
+
fig.update_layout(
155
+
mapbox= {
156
+
'style': "open-street-map",
157
+
'center': {'lon': -73, 'lat': 46 },
158
+
'zoom': 5},
159
+
showlegend=False)
160
+
161
+
fig.show()
162
+
```
163
+
<!-- #endregion -->
164
+
142
165
#### Reference
143
166
144
-
See https://plotly.com/python/reference/scattermapbox/ for more information about mapbox and their attribute options.
167
+
See https://plotly.com/python/reference/scattermap/ for available attribute options, or for `go.Scattermapbox`, see https://plotly.com/python/reference/scattermapbox/.
0 commit comments