question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Interactive plotting API

See original GitHub issue

We (@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:

  1. use it as a backend for - gdf.plot(backend="folium") or via global switch
  2. add it as a plotting kind - gdf.plot(kind="interactive/folium") or gdf.plot.interactive()
  3. 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:open
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
martinfleiscommented, May 3, 2021

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?

1reaction
martinfleiscommented, Apr 13, 2021

Does GeoDataFrame currently just override the pandas plot accessor?

@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 with folium backend you’ll be able to create a map but not e.g. bar plot. We may try to control kind="geo" backend independently / fallback to pandas default or something along that.

Personally I’d hope a better name than .interactive could be found though since it doesn’t suggest anything about plotting

Agree.


I now realised that I forgot to add plotly to the mix (cc @nicolaskruchten).

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the Best Interactive Plotting Package in Python?
I recently went on a deep dive into the interactive plotting ... Altair is a “declarative statistical visualization library” that uses the ...
Read more >
Martin Fleischmann on Twitter: "@geopandas If you want to share ...
We're working on interactive plotting for. @geopandas. based on @LeafletJS/folium. ... ENH: Interactive plotting API · Issue #1904 · geopandas/geopandas.
Read more >
5 Python Libraries for Creating Interactive Plots - Mode Analytics
Learn how to create interactive plots with Python with our 5 favorite Python visualization libraries. Make charts that you can embed online ......
Read more >
The difference between static and interactive plotting | Hands-On ...
The third plotting library, Bokeh, lets you plot interactive plots—plots that change when the user interacts with them. These plots are useful when...
Read more >
Which library should I use for my Python dashboard?
Data-visualization has a very wide scope, ranging from presenting data with simple charts to be included in a report, to complex interactive ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found