plotly_express
plotly_express copied to clipboard
Color line_mapbox by continuous variable
Is there a way to color a line_mapbox
plot by a continuous variable? It looks like when I specify the color
for a line_mapbox
as a continuous float column, the float is interpreted as a category:
import pandas as pd
import plotly_express as px
df = pd.read_csv('https://raw.githubusercontent.com/WillKoehrsen/Data-Analysis/master/nyc_traffic_data/nyc_traffic_speed_routes_sample.csv',
parse_dates=['time'])
px.set_mapbox_access_token(secrets['mapbox'])
px.line_mapbox(df.iloc[:10000],
lat='latitude', lon='longitude',
animation_frame='time', line_group='id',
animation_group='id',
color='speed', title='NYC Traffic Speeds',
height=800, zoom=9)
One solution would be to create my own column mapping the speeds to colors and then use that to color the lines, but I would still run into the issue of showing a legend. Thanks for the great library!
This will be a bit tricky... still thinking about the best way forward :)
Did this ever get resolved? I am interested in doing something similar.
Hi! I am also interested in doing the same. Have you solved it? Very nice library!
There is no support for this yet, no.
Thanks for the reply @nicolaskruchten !
would be a cool feature
any update on this? Did anyone find a workaround? I'm currently working on a project doing a similar thing...
@jamesrwrc, I ended up using geoviews' Path in place of this -- so, not a solution but an alternative package/tool:
import geoviews as gv
line_map = gv.Path(gdf, vdims=[var]).opts(
height = kwargs['height'],
width = kwargs['width'],
color = var,
colorbar = kwargs['colorbar'],
cnorm = kwargs['cnorm'],
cmap = kwargs['cmap'],
clim = (kwargs['vmin'],
kwargs['vmax']),
title = var,
) )
line_map * kwargs['basemap']