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/lines-on-mapbox.md
+60-24Lines changed: 60 additions & 24 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.4.2
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,26 +20,23 @@ jupyter:
20
20
name: python
21
21
nbconvert_exporter: python
22
22
pygments_lexer: ipython3
23
-
version: 3.7.7
23
+
version: 3.10.0
24
24
plotly:
25
-
description: How to draw a line on Map in Python with Plotly.
25
+
description: How to draw a line on tile-based maps in Python with Plotly.
26
26
display_as: maps
27
27
language: python
28
28
layout: base
29
-
name: Lines on Mapbox
29
+
name: Lines on Maps
30
30
order: 2
31
31
page_type: example_index
32
-
permalink: python/lines-on-mapbox/
32
+
permalink: python/lines-on-tile-maps/
33
+
redirect_from: python/lines-on-mapbox/
33
34
thumbnail: thumbnail/line_mapbox.jpg
34
35
---
35
36
36
-
### Mapbox Access Token and Base Map Configuration
37
+
### Lines on maps using Plotly Express
37
38
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
-
To draw a line on your map, you either can use [`px.line_mapbox()`](https://plotly.com/python-api-reference/generated/plotly.express.line_mapbox.html) in Plotly Express, or [`Scattermapbox`](https://plotly.com/python/reference/scattermapbox/) traces. Below we show you how to draw a line on Mapbox using Plotly Express.
41
-
42
-
### Lines on Mapbox maps using Plotly Express
39
+
To draw a line on a map, you either can use `px.line_map()` in Plotly Express, or `Scattermap` traces. Here's an example of drawing a line on a tile-based map using Plotly Express.
### Lines on Mapbox maps using `Scattermapbox` traces
99
+
### Lines on maps using `Scattermap` traces
103
100
104
-
This example uses `go.Scattermapbox` and sets
105
-
the [mode](https://plotly.com/python/reference/scattermapbox/#scattermapbox-mode) attribute to a combination of markers and line.
101
+
This example uses `go.Scattermap` and sets
102
+
the [mode](https://plotly.com/python/reference/scattermapbox/#scattermap-mode) attribute to a combination of markers and line.
103
+
104
+
```python
105
+
import plotly.graph_objects as go
106
+
107
+
fig = go.Figure(go.Scattermap(
108
+
mode="markers+lines",
109
+
lon= [10, 20, 30],
110
+
lat= [10, 20,30],
111
+
marker= {'size': 10}))
112
+
113
+
fig.add_trace(go.Scattermap(
114
+
mode="markers+lines",
115
+
lon= [-50, -60,40],
116
+
lat= [30, 10, -20],
117
+
marker= {'size': 10}))
118
+
119
+
fig.update_layout(
120
+
margin={'l':0,'t':0,'b':0,'r':0},
121
+
map= {
122
+
'center': {'lon': 10, 'lat': 10},
123
+
'style': "open-street-map",
124
+
'center': {'lon': -20, 'lat': -20},
125
+
'zoom': 1})
126
+
127
+
fig.show()
128
+
```
129
+
130
+
### Mapbox Maps
131
+
132
+
The earlier examples using `px.line_map` and `go.Scattermap` use Maplibre for rendering. These traces were introduced in Plotly.py 5.24. These trace types are now the recommended way to draw lines on tile-based maps. There are also traces that use Mapbox: `px.line_mapbox` and `go.Scattermapbox`
133
+
134
+
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.
135
+
136
+
To draw a line on your map, you either can use [`px.line_mapbox()`](https://plotly.com/python-api-reference/generated/plotly.express.line_mapbox.html) in Plotly Express, or [`Scattermapbox`](https://plotly.com/python/reference/scattermapbox/) traces. Below we show you how to draw a line on Mapbox using Plotly Express.
137
+
138
+
Here's an example of using `Scattermapbox`.
106
139
107
140
```python
108
141
import plotly.graph_objects as go
@@ -132,5 +165,8 @@ fig.show()
132
165
133
166
#### Reference
134
167
135
-
See [function reference for `px.(line_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.line_mapbox) or
136
-
https://plotly.com/python/reference/scattermapbox/ for more information about mapbox and their attribute options.
168
+
See [function reference for `px.(line_map)`](https://plotly.com/python-api-reference/generated/plotly.express.line_map) or
169
+
https://plotly.com/python/reference/scattermap/ for more information about the attributes available.
170
+
171
+
See Mapbox-based tile maps, see [function reference for `px.(line_mapbox)`](https://plotly.com/python-api-reference/generated/plotly.express.line_mapbox) or
0 commit comments