I’m trying to plot lat/lon points on a scattermapbox with a geojson file. I threw the geojson file in a panada’s data frame and made an empty list for lat and lon since thats all scattermapbox accepts. It didn’t turn out as expected. Haha
Dataframe:
0 [[[-105.077274, 40.514625], [-105.077005, 40.5...
1 [[[-105.024284, 40.509791], [-105.024274, 40.5...
2 [[[-105.087928, 40.578187], [-105.087939, 40.5...
3 [[[-105.11976, 40.589318], [-105.11977, 40.587...
4 [[[-105.083718, 40.568761], [-105.08459, 40.56...
...
995 [[[-105.05362, 40.525161], [-105.053607, 40.52...
996 [[[-105.030003, 40.62114], [-105.030012, 40.62...
997 [[[-105.123316, 40.560645], [-105.123353, 40.5...
998 [[[-105.070162, 40.580083], [-105.070175, 40.5...
999 [[[-105.120617, 40.560044], [-105.120637, 40.5...
Name: geometry_coordinates, Length: 1000, dtype: object
import plotly.graph_objects as go
import pandas as pd
from pandas.io.json import json_normalize
import json
geojson = json.load(open("Data/High Comfort Bike Lanes.geojson"))
geojson = json_normalize(geojson['features'], sep="_")
lon_comfortBike = []
lat_comfortBike = []
for l1 in geojson['geometry_coordinates']:
for l2 in l1:
for l3 in l2:
lon_comfortBike.append(l2[0])
lat_comfortBike.append(l2[1])
fig = go.Figure(
data=[
go.Scattermapbox(
name='High Comfort Bike Route',
hoverinfo='name',
lat=lat_comfortBike,
lon=lon_comfortBike,
mode="lines",
line=dict(width=3, color="#F00")
]
)
Any suggestions on how to loop through the data frame correctly and plot these lines?