ResidentMario / geoplot

High-level geospatial data visualization library for Python.
https://residentmario.github.io/geoplot/index.html
MIT License
1.14k stars 95 forks source link

New plot type: isopleth #63

Open stevenlis opened 5 years ago

stevenlis commented 5 years ago

I'm so glad to see a package that makes plotting geo heatmap this kind of easy and beautiful. After reading the API and I realize that the heatmaps produced by geoplot using seaborn represent the density of geo-events. I wonder if there is any way you can think of to use interpolation method to generate those kinds of heatmaps representing air pollution, temperature, etc.

I've been looking for a way to do this kind of plot for a white.

ResidentMario commented 5 years ago

Yes, geoplot.heatmap only works on point features lacking magnitudes. If you have gridded data with magnitudes, as in the cases you mentioned, this API won't work for you.

Heatmaps based on gridded magnitude data is a generalization of heatmaps based on point data, and I'm afraid there's quite a lot of math you or I would need to chew down to work an algorithm out. I don't personally know of any way to achieve this currently in Python.

I'd recommend creating a grid of squares around each observation, and plotting that as a choropleth. You can think of this as a pixelated heatmap.

stevenlis commented 5 years ago

@ResidentMario Indeed...I'm looking at this API from matplotlib and see if I can figure it out. Sadly, this heatmap thing is the only part that is missing from my complete python workflow. Thank you for your kind reply.

stevenlis commented 5 years ago

@ResidentMario I just saw a link at the bottom of this page in the GeoPandas doc.

ResidentMario commented 5 years ago

Very cool! Maybe an implementation is easier than I thought (just reuse this component).

stevenlis commented 5 years ago

@ResidentMario It would be great if there is a Python package that uses scipy interpolation module but is designed for geospatial point pattern analysis specifically like IDW and other more advanced methods.

stevenlis commented 5 years ago

@ResidentMario Here are some good resources.

https://mathlab.github.io/PyGeM/idw.html

https://stackoverflow.com/questions/3104781/inverse-distance-weighted-idw-interpolation-with-python

https://github.com/paulbrodersen/inverse_distance_weighting

ResidentMario commented 5 years ago

This is known as an isopleth in the literature.

xarray seems to able to do this: http://xarray.pydata.org/en/stable/examples/monthly-means.html

stevenlis commented 5 years ago

@ResidentMario The isopleth might be very useful but might not be what I was suggesting for since there are many methods for interpolation.

I just read a book this week and the author talked about a few different types of interpolation (e.g., IDW) often used in GIS in chapter 8 and shared his code here.

ResidentMario commented 5 years ago

Well, this feature request is for a plot function that takes point data with magnitudes as input, applies some sort of smoothing/interpolation function over it, and outputs a heatmap (which is an isopleth, in this context).

Interpolation can be tunable using a plot parameter. gplt.quadtree already defines an agg parameter for an aggregation function; an isopleth function could have a similar special parameter for a smoothing function whose default argument is an idw algorithm.

stevenlis commented 5 years ago

as an arg? man... I think I would like such an API design and am definitely looking forward to it!