ENH: Interactive plotting API
See original GitHub issueWe (@Sangarshanan and myself) are finishing the work on interactive plotting based on folium
- see https://github.com/martinfleis/geopandas-view for details on that and a notebook with examples - https://nbviewer.jupyter.org/github/martinfleis/geopandas-view/blob/main/examples.ipynb.
One of the major things now is to resolve the API. We can think of a few options:
- use it as a backend for -
gdf.plot(backend="folium")
or via global switch - add it as a plotting kind -
gdf.plot(kind="interactive/folium")
orgdf.plot.interactive()
- add it is an independent method -
gdf.interactive()
(or some other keyword).
The first and the second option can cause a bit of trouble since they may conflict with the existing pandas plotting backends but we would have to look into that.
I currently prefer the last option + mirroring the backend management pandas has for its plots. We would always get an interactive map from the gdf.interactive()
method. By default, the implementation based on folium but we can open the API to other options like ipyleaflet
or hvplot
to allow something like this:
gdf.interactive(column='foo', cmap='viridis', legend=True, backend='folium')
gdf.interactive(column='foo', cmap='viridis', legend=True, backend='ipyleaflet')
gdf.interactive(column='foo', cmap='viridis', legend=True, backend='hvplot')
# or ideally with some global switch
gpd.options.interactive.backend = "backend.module"
Links to ipyleaflet and hvplot should not be complicated given their current support of geodataframes and can be done in downstream.
Another argument for an independent method is the potential to expand it with other plotting kinds as MarkerCluster
or Heatmap
-> gdf.interactive.markercluster()
. Having it separated from the plot
API feels like the cleanest solution.
cc-ing @jbednar and @philippjfr for hvplot
and @martinRenou for ipyleaflet
to get your views on the idea of interactive backends (whether it is worth doing from your perspective).
To give you a bit of a context why we decided to go with folium instead of other options: we wanted to go with leaflet.js as it is widely used across the ecosystem (in both Python and R) and has the Google maps-like feeling people are used to. Between folium
and ipyleaflet
, the former is much lighter and does not depend on Jupyter lab (GeoPandas has a lot of users not working with JL so it would be suboptimal to support interactive plotting only under JL).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (4 by maintainers)
I think that https://github.com/martinfleis/geopandas-view is ready to be merged in geopandas so the remaining part to figure out is the API.
ping @geopandas/collaborators & @Sangarshanan - what are your thoughts on this?
@philippjfr Yes but the full pandas functionality including backends still works as you know it. We just change the default to use
kind="geo"
which uses our internal mapping module no matter the backend.If I read your suggestion correctly, you’d keep the API as
gdf.plot()
and change backends between matplotlib, folium, holoviews etc.? The tricky aspect of that is that withfolium
backend you’ll be able to create a map but not e.g. bar plot. We may try to controlkind="geo"
backend independently / fallback to pandas default or something along that.Agree.
I now realised that I forgot to add plotly to the mix (cc @nicolaskruchten).