geoplot.kdeplot(df, projection=None, extent=None, figsize=(8, 6), ax=None, clip=None, **kwargs)¶Geographic kernel density estimate plot.
| Parameters: |
|
|---|---|
| Returns: | The axis object with the plot on it. |
| Return type: | AxesSubplot or GeoAxesSubplot instance |
Examples
Give it a dataset containing a geometry of shapely Point observations, and kdeplot will return a
geospatial kernel density estimate plot
showing where they are.
A basic kdeplot specified data and, optionally, a projection.
import geoplot as gplt
import geoplot.crs as gcrs
gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea())
However, kdeplots need additional geospatial context to be interpretable. In this case (and for the remainder of the examples) we will provide this by overlaying borough geometry.
ax = gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea())
gplt.polyplot(boroughs, projection=gcrs.AlbersEqualArea(), ax=ax)
Most of the rest of the parameters to kdeplot are parameters inherited from the seaborn method by the same
name, on which this plot type is
based. For example, specifying shade=True provides a filled KDE instead of a contour one:
ax = gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea(),
shade=True)
gplt.polyplot(boroughs, projection=gcrs.AlbersEqualArea(), ax=ax)
Use n_levels to specify the number of contour levels.
ax = gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea(),
n_levels=30)
gplt.polyplot(boroughs, projection=gcrs.AlbersEqualArea(), ax=ax)
Or specify cmap to change the colormap.
ax = gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea(),
cmap='Purples')
gplt.polyplot(boroughs, projection=gcrs.AlbersEqualArea(), ax=ax)
Oftentimes given the geometry of the location, a “regular” continuous KDEPlot doesn’t make sense. We can specify a
clip of iterable geometries, which will be used to trim the kdeplot (note: if you have set shade=True as
a parameter you may need to additionally specify shade_lowest=False to avoid inversion at the edges).
gplt.kdeplot(collisions, projection=gcrs.AlbersEqualArea(),
shade=True, clip=boroughs)