Skip to content Skip to sidebar Skip to footer

Plot Heatmap (kdeplot) With Geopandas

I have the following data stored in a geopandas.DataFrame object. geometry are polygons and x are the values I want to use as a heat scale. id

Solution 1:

I was recommended to use geoplot.

geoplot.kdeplot expects a geopandas.DataFrame object with one row per Point. That is, something along the lines of:

        PointID                     geometry
0204403876  POINT (-101.6670021.11670)
1204462769  POINT (-101.6670021.11670)
2144407530  POINT (-101.6670021.11670)
3118631118  POINT (-101.6670021.11670)
4118646035  POINT (-101.6670021.11670)

And then plot these points over the map, which is passed as a separate object.

To show this in code, suppose the polygons are stored in df_map and the points are stored in df_points.

# Import geoplotimport geoplot
import geoplot.crs as gcrs

# Plot heatmap
ax = geoplot.kdeplot(df_points, projection=gcrs.AlbersEqualArea())

# Add polygons
geoplot.polyplot(df_map, ax=ax)

Which should yield something along the lines of this.

nice heatmap

Sadly, I cannot post my results because projection=gcrs.AlbersEqualArea() crashes my session, but I hope this helps someone in the future.

Post a Comment for "Plot Heatmap (kdeplot) With Geopandas"