pynbody.plot.generic.gauss_kde#
- pynbody.plot.generic.gauss_kde(xo, yo, weights=None, mass=None, gridsize=(100, 100), nbins=None, make_plot=True, nmin=None, nmax=None, **kwargs)[source]#
Plot 2D gaussian kernel density estimate (KDE) given values at points (x, y).
Behavior changes depending on which keywords are passed:
If a weights array is supplied, produce a weighted KDE.
If a mass array is supplied, a mass density is computed.
If both weights and mass are supplied, a mass-averaged KDE of the weights is computed.
By default, norm=False is passed to
fast_kde()
meaning that the result returned is not normalized such that the integral over the area equals one.- Since this function produces a density estimate, the units of the
output grid are different than for the output of
hist2d()
. To get to the same units, you must multiply by the size of the cells.Input:
xo: array
yo: array
Optional keywords:
- mass: numpy array of same length as x and y
particle masses to be used for weighting
- weights: numpy array of same length as x and y
if weights is passed, color corresponds to the mean value of weights in each cell
- nmin: float (default None)
if weights and mass are both specified, the mass-weighted contours are only drawn where the mass exceeds nmin.
- gridsize: (int, int) (default: 100,100)
size of grid for computing the density estimate
- nbins: int
number of bins for the histogram - if specified, gridsize is set to (nbins,nbins)
- make_plot: boolean (default: True)
whether or not to produce a plot
Keywords passed to
fast_kde()
:- norm: boolean (default: False)
If False, the output is only corrected for the kernel. If True, the result is normalized such that the integral over the area yields 1.
- nocorrelation: (default: False) If True, the correlation
between the x and y coords will be ignored when preforming the KDE.
Keywords passed to
make_contour_plot()
:- x_range: list, array, or tuple
size(x_range) must be 2. Specifies the X range.
- y_range: tuple
size(y_range) must be 2. Specifies the Y range.
- nlevels: int
number of levels to use for the contours
- logscale: boolean
whether to use log or linear spaced contours
- colorbar: boolean
draw a colorbar
- scalemin: float
minimum value to use for the color scale
- scalemax: float
maximum value to use for the color scale