pointpats.plot_density

pointpats.plot_density(data, bandwidth, kernel=None, resolution=100, levels=10, fill=False, margin=0.1, ax=None, figsize=None, **kwargs)[source]

Plot kernel density of a given point pattern

The KDE can be done either using statsmodels.nonparametric.KDEMultivariate, which is used when kernel=None, or using KDEpy.FFTKDE when kernel is set. FFTKDE tends to be generally faster in most cases but may need different than "gaussian" kernel to resolve in some cases. For small data of up to 10 000 points, the difference is not noticeable. For larger data, specify bandwidth to enforce the use of FFTKDE. Note that while being faster, FFTKDE may in some case result in erroneous KDE.

KDE is plotted using matplotlib’s contour() or contourf() function to plot the density.

If MultiPoints are given, each point is treated as separate observation.

Parameters:
dataarray or geopandas object

Array with a shape (2, n) containing coordinates of points or a geopandas object with (Multi)Point geometry. Assumes projected coordinates, geographical coordinates (latitude, longitude) are not supported.

bandwidthfloat

bandwidth in the units of CRS in which data is

kernelstr | None, optional

The kernel function. If None, defaults to the Gaussian kernel and statsmodels implementation. If set, uses KDEpy implementation. See KDEpy.FFTKDE._available_kernels.keys() for choices.

resolutionint | tuple(int, int), optional

resolution of the grid used to evaluate the probability density function. If tuple, each dimension of the grid is specified separately. By default 100

levelsint or array-like, optional

Determines the number and positions of the contour lines / regions. See the documentation of contour() for details. By default 10

fillbool, optional

Fill the area between contour lines, by default False

marginfloat, optional

The factor of the margin by which the extent of the data will be expanded when creating the grid. 0.1 means 10% on each side, by default 0.1. Only used with the statsmodels implementation.

axmatplotlib.axes.Axes (default None)

axes on which to draw the plot

figsizetuple of integers (default None)

Size of the resulting matplotlib.figure.Figure. If the argument ax is given explicitly, figsize is ignored.

**kwargs

Keyword arguments passed to contour() or contourf() used for further styling of the plot, for example cmap, linewidths, linestyles, or alpha. See the documentation of contour() for details.

Returns:
matplotlib.axes.Axes

matplotlib axes instance with the contour plot