geocompx / geocompy

Geocomputation with Python: an open source book
https://py.geocompx.org/
Other
300 stars 54 forks source link

Use explore instead of hvplot for geopandas #29

Closed martinfleis closed 10 months ago

martinfleis commented 2 years ago

Hey,

this is a great initiative! Thanks! I was checking the section 2 and noticed that in 2.2.2 you try to get an interactive plot using hvplot. I would suggest going with the built-in explore method as it is already there and you don't need any other external package. So unless you really prefer holoviews or need to do something explore cannot, I believe it is better to point users to the built in interactive plotting. Depending on folium and leaflet instead of hvplot is also much more lightweight.

Robinlovelace commented 2 years ago

Thanks for the heads-up Martin, that is a great insight. Reduced imports are good. Looking here, geopandas_object.explore(arguments...) looks promising, any advice on how to use it? https://towardsdatascience.com/interactive-geographical-maps-with-geopandas-4586a9d7cc10

martinfleis commented 2 years ago

The API of explore is almost the same as for plot, with a few minor differences related to interactivity. The core of it is illustrated in the docs https://geopandas.org/en/stable/docs/user_guide/interactive_mapping.html. For most of the stuff, you should be just able to replace gdf.plot(...) with gdf.explore(...) and it should show the same map, just in leaflet instead of matplotlib. Let me know if you'll have any specific questions on how to use that.

Robinlovelace commented 2 years ago

Sounds good, will give it a spin 👍

michaeldorman commented 2 years ago

Nice! Wasn't aware of .explore, it looks great!

anitagraser commented 2 years ago

Unfortunately, there seems to be another issue with hvplot in the context of this book: the interactive plots are not displayed in the Quarto HTML exports (The error is: "Unable to display output for mime type(s):")

Robinlovelace commented 2 years ago

.explore() all the way for now then?!

michaeldorman commented 2 years ago

I'm in favor of using just .explore in the basic interactive plots (if any) in Chapters 1-8. In Chapter 9 "Interactive Mapping" section we can use more specialized methods, we can explore if hvplot issue can be solved or if there is another good alternative.

martinfleis commented 2 years ago

IMHO hvplot is not among the most used libraries for interactive mapping (based purely on a feeling, not numbers, no idea where to get those). I know that @anitagraser depends on it in movingpandas but I think that most of people will first go for ipyleaflet or custom folium solutions if GeoDataFrame.explore() is not enough.

Robinlovelace commented 2 years ago

This is good feedback, may thanks Martin! Also interested in ppls thoughts on leafmap.

martinfleis commented 2 years ago

leafmap is built on top of ipyleaflet and folium and is aimed at people who try to avoid code. I am sure it will become quite popular but the main question here is who is the audience of your book. If you try to teach ppl how to code, I'd focus on libraries based on code, not UI.

anitagraser commented 2 years ago

most of people will first go for ipyleaflet or custom folium solutions

Yes, that's definitely in line with my observations so far. Not sure why, however. Naturally, it helps that many people are familiar with Leaflet.

martinfleis commented 2 years ago

I personally don't like the feeling of hvplot as it is less google mappy than leaflet is. And installation is hefty compared to folium.

anitagraser commented 2 years ago

I personally don't like the feeling of hvplot as it is less google mappy than leaflet is. And installation is hefty compared to folium.

I completely understand that argument. Activating mouse wheel zoom is one of the first things I do for GeoViews applications. But it definitely still feels different.

Personally, for me, the seamless integration of spatial and non-spatial plots that hvplot (with GeoViews) provides is the main argument pro hvplot in data science settings. I don't know of any other API that does this so well. In my experience, non-geo folks can be really reluctant to learn yet another API just to get some maps.