Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better support for lines on maps in Plotly Express #2601

Open
nicolaskruchten opened this issue Jun 25, 2020 · 13 comments
Open

better support for lines on maps in Plotly Express #2601

nicolaskruchten opened this issue Jun 25, 2020 · 13 comments
Labels
feature something new P3 backlog
Milestone

Comments

@nicolaskruchten
Copy link
Contributor

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.

@nicolaskruchten nicolaskruchten added this to the v4.x milestone Jun 25, 2020
@nicolaskruchten
Copy link
Contributor Author

See also plotly/plotly_express#29

@harisbal
Copy link

harisbal commented 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
Copy link
Contributor Author

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
Copy link
Contributor Author

People working with geospatial data are very used to be able to control the width, apart form the color of the line.

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
Copy link
Contributor Author

@alexcjohnson what's your instinct on something like this? a new PX function or a new geojson argument that in this case wouldn't map straight down to a trace-level geojson schema 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-geopandas

@alexcjohnson
Copy link
Collaborator

@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.

@nicolaskruchten
Copy link
Contributor Author

Actually all the other args except lat/Lon/line_group would work! Color, line_width, eventually facet etc

@alexcjohnson
Copy link
Collaborator

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
Copy link

harisbal commented Oct 17, 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_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.

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
Copy link

Just wanted to give this a bump!

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.

Thanks for all the work so far though! 🙂

@ibhalin
Copy link

ibhalin commented Nov 25, 2020

I'm bumping too. It would be fantastic !

@beajifu
Copy link

beajifu commented 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.

@gvwilson gvwilson self-assigned this Jul 5, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added the P3 backlog label Aug 12, 2024
@gvwilson gvwilson changed the title Plotly Express lines on maps better support for lines on maps in Plotly Express Aug 12, 2024
@gvwilson gvwilson added the feature something new label Aug 12, 2024
@gvwilson
Copy link
Contributor

@archmoj will your recent work address this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new P3 backlog
Projects
None yet
Development

No branches or pull requests

7 participants