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.2 '
9+ jupytext_version : 1.4.2
1010 kernelspec :
1111 display_name : Python 3
1212 language : python
@@ -20,7 +20,7 @@ jupyter:
2020 name : python
2121 nbconvert_exporter : python
2222 pygments_lexer : ipython3
23- version : 3.6.8
23+ version : 3.7.7
2424 plotly :
2525 description : How to draw a line on Map in Python with Plotly.
2626 display_as : maps
@@ -57,6 +57,48 @@ fig.update_layout(mapbox_style="stamen-terrain", mapbox_zoom=4, mapbox_center_la
5757fig.show()
5858```
5959
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+
60102### Lines on Mapbox maps using ` Scattermapbox ` traces
61103
62104This example uses ` go.Scattermapbox ` and sets
@@ -90,4 +132,4 @@ fig.show()
90132
91133#### Reference
92134
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