You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
better support for lines on maps in Plotly Express #2601
Today, px.line_mapbox and px.line_geo expect rows which are points, which are then split into groups and connected by lines.
In most GIS formats, however, as wrapped by GeoPandas, the entire line feature is often stored in a single row, just like choropleth geometries. We should have either a new pair of PX functions for this (px.line_feature_mapbox?) or an option to the existing functions (px.line_mapbox(geojson=<geojson>)) to support this option out of the box.
This will be a game changing enhancement since it will make plotly a viable alternative for representing geospatial data instead of GIS software.
In addition I would like to suggest the following:
People working with geospatial data are very used to be able to control the width, apart form the color of the line.
I suppose this can be achieved already by iterating over each line and adjusting its width. However, straightforwardly providing this capability in px would be very useful.
Cheers
Thanks for the enthusiasm @harisbal! What would you see the function signature looking like in this case? I hesitate a bit about making px.line_mapbox have in effect different "modes" but maybe this is the right way forward.
@nicolaskruchten Feels like various other of the args to px.line_mapbox wouldn't make sense with this kind of input data, and if that's the case then perhaps a new function is a cleaner solution.
Oh OK, I thought it seemed like the data structure would be fairly different so wouldn't support other args the same way - but if it does, then great, just overload the same function!
Thanks for the enthusiasm @harisbal! What would you see the function signature looking like in this case? I hesitate a bit about making px.line_mapbox have in effect different "modes" but maybe this is the right way forward.
I believe that a mode argument would be very useful here. The two possible modes would be either points or linestrings.
In addition, I feel that for the points case a line_order argument should be also introduced to specify the order of the points.
Out-of-the-box support for shapely/GeoPandas LineStrings would be fantastic. I'm aware you've added some support for Shapely Points and Polygons. The GeoPandas support example given in Lines on Maps is useful but it doesn't really exploit the strengths of pandas, as it involves unpacking the dataframe using a loop.
I want to ask if there is any progress for this feature, because it sounds really good to have support for LineStrings to easily plot a GeoPandas Dataframe. I would appreciate it.
Activity
nicolaskruchten commentedon Oct 16, 2020
See also plotly/plotly_express#29
harisbal commentedon Oct 16, 2020
This will be a game changing enhancement since it will make plotly a viable alternative for representing geospatial data instead of GIS software.
In addition I would like to suggest the following:
People working with geospatial data are very used to be able to control the width, apart form the color of the line.
I suppose this can be achieved already by iterating over each line and adjusting its width. However, straightforwardly providing this capability in px would be very useful.
Cheers
nicolaskruchten commentedon Oct 16, 2020
Thanks for the enthusiasm @harisbal! What would you see the function signature looking like in this case? I hesitate a bit about making
px.line_mapboxhave in effect different "modes" but maybe this is the right way forward.nicolaskruchten commentedon Oct 16, 2020
Yes, this is indeed a limitation we have right now... we don't provide fine-grained control over width and color per segment, but per line we could.
nicolaskruchten commentedon Oct 16, 2020
@alexcjohnson what's your instinct on something like this? a new PX function or a new
geojsonargument that in this case wouldn't map straight down to a trace-levelgeojsonschema attribute? this new argument would be parsed similarly to the iterative approach in the docs here: https://plotly.com/python/lines-on-mapbox/#lines-on-mapbox-maps-from-geopandasalexcjohnson commentedon Oct 16, 2020
@nicolaskruchten Feels like various other of the args to
px.line_mapboxwouldn't make sense with this kind of input data, and if that's the case then perhaps a new function is a cleaner solution.nicolaskruchten commentedon Oct 16, 2020
Actually all the other args except lat/Lon/line_group would work! Color, line_width, eventually facet etc
alexcjohnson commentedon Oct 17, 2020
Oh OK, I thought it seemed like the data structure would be fairly different so wouldn't support other args the same way - but if it does, then great, just overload the same function!
harisbal commentedon Oct 17, 2020
I believe that a
modeargument would be very useful here. The two possible modes would be eitherpointsorlinestrings.In addition, I feel that for the
pointscase aline_orderargument should be also introduced to specify the order of the points.So in case someone has data as points:
px.line_mapbox(df, mode='points', lat='lat, lon='lon', line_group='country', line_order='order')And in case someone has a geodataframe with linestrings:
px.line_mapbox(dfg, mode='linestrings', linestrings=dfg.geometry)I'd be glad to help if required. Cheers
EsbernJakobsen commentedon Oct 26, 2020
Just wanted to give this a bump!
Out-of-the-box support for shapely/GeoPandas
LineStringswould be fantastic. I'm aware you've added some support for ShapelyPointsandPolygons. The GeoPandas support example given in Lines on Maps is useful but it doesn't really exploit the strengths of pandas, as it involves unpacking the dataframe using a loop.Thanks for all the work so far though! 🙂
ibhalin commentedon Nov 25, 2020
I'm bumping too. It would be fantastic !
beajifu commentedon Feb 16, 2023
I want to ask if there is any progress for this feature, because it sounds really good to have support for LineStrings to easily plot a GeoPandas Dataframe. I would appreciate it.
[-]Plotly Express lines on maps[/-][+]better support for lines on maps in Plotly Express[/+]gvwilson commentedon Aug 12, 2024
@archmoj will your recent work address this?