Skip to content

Commit a913463

Browse files
committed
update to new map types
1 parent a4a785e commit a913463

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

doc/python/lines-on-mapbox.md

Lines changed: 60 additions & 24 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.2'
9-
jupytext_version: 1.4.2
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,26 +20,23 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.7.7
23+
version: 3.10.0
2424
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.
2626
display_as: maps
2727
language: python
2828
layout: base
29-
name: Lines on Mapbox
29+
name: Lines on Maps
3030
order: 2
3131
page_type: example_index
32-
permalink: python/lines-on-mapbox/
32+
permalink: python/lines-on-tile-maps/
33+
redirect_from: python/lines-on-mapbox/
3334
thumbnail: thumbnail/line_mapbox.jpg
3435
---
3536

36-
### Mapbox Access Token and Base Map Configuration
37+
### Lines on maps using Plotly Express
3738

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

4441
```python
4542
import pandas as pd
@@ -49,17 +46,17 @@ us_cities = us_cities.query("State in ['New York', 'Ohio']")
4946

5047
import plotly.express as px
5148

52-
fig = px.line_mapbox(us_cities, lat="lat", lon="lon", color="State", zoom=3, height=300)
49+
fig = px.line_map(us_cities, lat="lat", lon="lon", color="State", zoom=3, height=300)
5350

54-
fig.update_layout(mapbox_style="open-street-map", mapbox_zoom=4, mapbox_center_lat = 41,
51+
fig.update_layout(map_style="open-street-map", map_zoom=4, map_center_lat = 41,
5552
margin={"r":0,"t":0,"l":0,"b":0})
5653

5754
fig.show()
5855
```
5956

60-
### Lines on Mapbox maps from GeoPandas
57+
### Lines on maps from GeoPandas
6158

62-
Given a GeoPandas geo-data frame with `linestring` or `multilinestring` features, one can extra point data and use `px.line_mapbox()`.
59+
Given a GeoPandas geo-data frame with `linestring` or `multilinestring` features, one can extra point data and use `px.line_map()`.
6360

6461
```python
6562
import plotly.express as px
@@ -94,15 +91,51 @@ for feature, name in zip(geo_df.geometry, geo_df.name):
9491
lons = np.append(lons, None)
9592
names = np.append(names, None)
9693

97-
fig = px.line_mapbox(lat=lats, lon=lons, hover_name=names,
98-
mapbox_style="open-street-map", zoom=1)
94+
fig = px.line_map(lat=lats, lon=lons, hover_name=names,
95+
map="open-street-map", zoom=1)
9996
fig.show()
10097
```
10198

102-
### Lines on Mapbox maps using `Scattermapbox` traces
99+
### Lines on maps using `Scattermap` traces
103100

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`.
106139

107140
```python
108141
import plotly.graph_objects as go
@@ -132,5 +165,8 @@ fig.show()
132165

133166
#### Reference
134167

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
172+
https://plotly.com/python/reference/scattermapbox/.

0 commit comments

Comments
 (0)