I am trying to highlight particular lines in a px.line_mapbox, I tried using color discrete but couldn’t figure that out using a geodataframe. So I thought to merge two line graphs into one of different colors, but this doesn’t seem to work either. What is the best way to color a few lines in a px.line_mapbox based on a particular attribute from a callback?
def getLines(gdf):
lats = []
lons = []
names = []
for feature, name in zip(gdf.geometry, gdf.Name):
if isinstance(feature, shapely.geometry.linestring.LineString):
linestrings = [feature]
elif isinstance(feature, shapely.geometry.multilinestring.MultiLineString):
linestrings = feature.geoms
else:
continue
for linestring in linestrings:
x, y = linestring.xy
lats = np.append(lats, y)
lons = np.append(lons, x)
names = np.append(names, [name]*len(y))
lats = np.append(lats, None)
lons = np.append(lons, None)
names = np.append(names, None)
return lats, lons, names
gdf = src_gdf.query('names != "Line 1"')
lats, lons, names = getLines(gdf)
boxfig = px.line_mapbox(lat=lats, lon=lons, hover_name=names,
mapbox_style="stamen-terrain", zoom=5)
boxfig.update_traces(line_color='#0000ff', line_width=2)
getdf = geo_df2.query('names == "Line 1"')
lat, lon, _ = getLines(getdf)
boxfig2 = px.line_mapbox(lat=lat, lon=lon,)
boxfig2.update_traces(line_color='#FF5733', line_width=2)
boxfig.add_trace(boxfig2)
What i am trying to do is load the start and end points for geographic locations, then highlight certain routes based on my callbacks.
Would anyone know the best way to do this?