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.2 '
9
+ jupytext_version : 1.4.2
10
10
kernelspec :
11
11
display_name : Python 3
12
12
language : python
@@ -20,7 +20,7 @@ jupyter:
20
20
name : python
21
21
nbconvert_exporter : python
22
22
pygments_lexer : ipython3
23
- version : 3.6.8
23
+ version : 3.7.7
24
24
plotly :
25
25
description : How to draw a line on Map in Python with Plotly.
26
26
display_as : maps
@@ -57,6 +57,48 @@ fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_la
57
57
fig.show()
58
58
```
59
59
60
+ ### Lines on Mapbox maps from GeoPandas
61
+
62
+ Given a GeoPandas geo-data frame with ` linestring ` or ` multilinestring ` features, one can extra point data and use ` px.line_mapbox() ` .
63
+
64
+ ``` python
65
+ import plotly.express as px
66
+ import geopandas as gpd
67
+ import shapely.geometry
68
+ import numpy as np
69
+ import wget
70
+
71
+ # download a zipped shapefile
72
+ wget.download(" https://plotly.github.io/datasets/ne_50m_rivers_lake_centerlines.zip" )
73
+
74
+ # open a zipped shapefile with the zip:// pseudo-protocol
75
+ geo_df = gpd.read_file(" zip://ne_50m_rivers_lake_centerlines.zip" )
76
+
77
+ lats = []
78
+ lons = []
79
+ names = []
80
+
81
+ for feature, name in zip (geo_df.geometry, geo_df.name):
82
+ if isinstance (feature, shapely.geometry.linestring.LineString):
83
+ linestrings = [feature]
84
+ elif isinstance (feature, shapely.geometry.multilinestring.MultiLineString):
85
+ linestrings = feature.geoms
86
+ else :
87
+ continue
88
+ for linestring in linestrings:
89
+ x, y = linestring.xy
90
+ lats = np.append(lats, y)
91
+ lons = np.append(lons, x)
92
+ names = np.append(names, [name]* len (y))
93
+ lats = np.append(lats, None )
94
+ lons = np.append(lons, None )
95
+ names = np.append(names, None )
96
+
97
+ fig = px.line_mapbox(lat = lats, lon = lons, hover_name = names,
98
+ mapbox_style = " stamen-terrain" , zoom = 0 )
99
+ fig.show()
100
+ ```
101
+
60
102
### Lines on Mapbox maps using ` Scattermapbox ` traces
61
103
62
104
This example uses ` go.Scattermapbox ` and sets
@@ -90,4 +132,4 @@ fig.show()
90
132
91
133
#### Reference
92
134
93
- See https://plotly.com/python/reference/scattermapbox/ for more information about mapbox and their attribute options.
135
+ See https://plotly.com/python/reference/scattermapbox/ for more information about mapbox and their attribute options.
0 commit comments