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

lonboard backend for geopandas explore #412

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

knaaptime
Copy link
Member

@knaaptime knaaptime commented Jan 1, 2025

add explore-like function to generate a lonboard choropleth quickly from a geodataframe. It needs testing and a few checks (like checking length if passing color directly instead of a string) but otherwise has parity, essentially with gdf.explore. The lonboard linear scaler works a little differently than the default explore (I don't think the discrepancy is wrong, just different implementations), but the purpose here is really to use mapclassify, so I'm not too concerned. Some things may not be perfectly in sync with explore, for instance categorical maps will throw an error if you try to plot with a continuous colormap. While catching that might be good, I'm fine with that (correct) behavior as default.

@knaaptime
Copy link
Member Author

knaaptime commented Jan 1, 2025

lonboard is wicked flexible as a widget and can update the map (e.g. change colors, add layers) on the fly and without redrawing that map, which makes it relatively simple to implement an interactive version of the animated maps, like with something as simple as

from time import sleep
for i in range(10):
    for color in ['yellow','red', 'blue']:
        m.layers[0].get_fill_color = color
        sleep(.5)
    sleep(1)

and you could very easily add widgets that control the speed of animation, etc

@knaaptime
Copy link
Member Author

following martin's suggestion, it would be cool to implement the plotting (this, the animation, and the timeseries plot--maybe others) as methods on a geodataframe https://pandas.pydata.org/docs/development/extending.html using the extension framework

when we first started geosnap, everything used a clumsy class-based approach that was little more than a wrapper around a geodataframe because the extension api wasn't available at the time

@knaaptime
Copy link
Member Author

ok this is pretty neat actually. The latest commit moves the function into an explore method under the gvz namespace, e.g.

gdf.explore()
for classic folium backend, and

gdf.gvz.explore()
for a lonboard backend

fixed a scalar issue with non-classified maps, so the API is identical as possible and both produce identical results. The only remaining difference is you still cant use continuous colormaps with categorical data--which again, I think is ok but could still probably be solved easily

full demo notebook here but the lonboard maps don't get embedded

https://gist.github.com/knaaptime/6f6c4f1ae7ce6b156b4cfbcc6b029f98

@knaaptime knaaptime changed the title dexplore function lonboard backend for geopandas explore Jan 4, 2025
@knaaptime
Copy link
Member Author

categorical maps can take any cmap now (even animation works as expected). Pretty sure this is as close to matching vanilla explore as possible (though needs a few more input checks). Thanks for the extension tip @martinfleis, this seems to work really nicely :)

(though welcome any input if you have any)

@martinfleis
Copy link

from a quick glance looks okay to me

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

Successfully merging this pull request may close these issues.

2 participants