Skip to content

Commit 9dc8202

Browse files
committed
add new map types
1 parent 608d114 commit 9dc8202

File tree

1 file changed

+51
-28
lines changed

1 file changed

+51
-28
lines changed

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

Lines changed: 51 additions & 28 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.1'
9-
jupytext_version: 1.1.1
8+
format_version: '1.3'
9+
jupytext_version: 1.16.3
1010
kernelspec:
11-
display_name: Python 3
11+
display_name: Python 3 (ipykernel)
1212
language: python
1313
name: python3
1414
language_info:
@@ -20,68 +20,63 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.8
23+
version: 3.10.0
2424
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.
2626
display_as: maps
2727
language: python
2828
layout: base
2929
name: Filled Area on Maps
3030
order: 3
3131
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/
3334
thumbnail: thumbnail/area.jpg
3435
---
3536

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:
4138

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
4342

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
4844

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'
5246

5347
```python
5448
import plotly.graph_objects as go
5549

56-
fig = go.Figure(go.Scattermapbox(
50+
fig = go.Figure(go.Scattermap(
5751
fill = "toself",
5852
lon = [-74, -70, -70, -74], lat = [47, 47, 45, 45],
5953
marker = { 'size': 10, 'color': "orange" }))
6054

6155
fig.update_layout(
62-
mapbox = {
56+
map = {
6357
'style': "open-street-map",
6458
'center': {'lon': -73, 'lat': 46 },
6559
'zoom': 5},
6660
showlegend = False)
6761

6862
fig.show()
63+
6964
```
7065

71-
### Multiple Filled Areas with a `Scattermapbox` trace
66+
### Multiple Filled Areas with a `Scattermap` trace
7267

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.
7469

7570
```python
7671
import plotly.graph_objects as go
7772

78-
fig = go.Figure(go.Scattermapbox(
73+
fig = go.Figure(go.Scattermap(
7974
mode = "lines", fill = "toself",
8075
lon = [-10, -10, 8, 8, -10, None, 30, 30, 50, 50, 30, None, 100, 100, 80, 80, 100],
8176
lat = [30, 6, 6, 30, 30, None, 20, 30, 30, 20, 20, None, 40, 50, 50, 40, 40]))
8277

8378
fig.update_layout(
84-
mapbox = {'style': "open-street-map", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
79+
map = {'style': "open-street-map", 'center': {'lon': 30, 'lat': 30}, 'zoom': 2},
8580
showlegend = False,
8681
margin = {'l':0, 'r':0, 'b':0, 't':0})
8782

@@ -95,13 +90,13 @@ In this map we add a GeoJSON layer.
9590
```python
9691
import plotly.graph_objects as go
9792

98-
fig = go.Figure(go.Scattermapbox(
93+
fig = go.Figure(go.Scattermap(
9994
mode = "markers",
10095
lon = [-73.605], lat = [45.51],
10196
marker = {'size': 20, 'color': ["cyan"]}))
10297

10398
fig.update_layout(
104-
mapbox = {
99+
map = {
105100
'style': "open-street-map",
106101
'center': { 'lon': -73.6, 'lat': 45.5},
107102
'zoom': 12, 'layers': [{
@@ -139,6 +134,34 @@ fig.update_layout(
139134
fig.show()
140135
```
141136

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+
142165
#### Reference
143166

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

Comments
 (0)