plotnine.stats.stat_density

class plotnine.stats.stat_density(*args, **kwargs)[source]

Compute density estimate

Usage

stat_density(mapping=None, data=None, geom='density', position='stack',
             na_rm=False, n=1024, adjust=1, cut=3, clip=(-inf, inf),
             trim=False, kernel='gaussian', bw='normal_reference',
             gridsize=None, **kwargs)

Only the mapping and data can be positional, the rest must be keyword arguments. **kwargs can be aesthetics (or parameters) used by the geom.

Parameters:
mapping : aes, optional

Aesthetic mappings created with aes(). If specified and inherit.aes=True, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.

Aesthetic Default value
x  
y 'stat(density)'

The bold aesthetics are required.

Options for computed aesthetics

'density'   # density estimate

'count'     # density * number of points,
              # useful for stacked density plots

'scaled'    # density estimate, scaled to maximum of 1
data : dataframe, optional

The data to be displayed in this layer. If None, the data from from the ggplot() call is used. If specified, it overrides the data from the ggplot() call.

geom : str or stat, optional (default: density)

The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.

position : str or position, optional (default: stack)

Position adjustment. If it is a string, it must be registered and known to Plotnine.

na_rm : bool, optional (default: False)

If False, removes missing values with a warning. If True silently removes missing values.

kernel : str, optional (default: 'gaussian')

Kernel used for density estimation. One of:

'biweight'
'cosine'
'cosine2'
'epanechnikov'
'gaussian'
'triangular'
'triweight'
'uniform'
adjust : float, optional (default: 1)

An adjustment factor for the bw. Bandwidth becomes bw * adjust. Adjustment of the bandwidth.

trim : bool, optional (default: False)

This parameter only matters if you are displaying multiple densities in one plot. If False, the default, each density is computed on the full range of the data. If True, each density is computed over the range of that group; this typically means the estimated x values will not line-up, and hence you won't be able to stack density values.

n : int, optional(default: 1024)

Number of equally spaced points at which the density is to be estimated. For efficient computation, it should be a power of two.

gridsize : int, optional (default: None)

If gridsize is None, max(len(x), 50) is used.

bw : str or float, optional (default: 'normal_reference')

The bandwidth to use, If a float is given, it is the bandwidth. The str choices are:

'normal_reference'
'scott'
'silverman'
cut : float, optional (default: 3)

Defines the length of the grid past the lowest and highest values of x so that the kernel goes to zero. The end points are -/+ cut*bw*{min(x) or max(x)}.

clip : tuple, optional (default: (-np.inf, np.inf))

Values in x that are outside of the range given by clip are dropped. The number of values in x is then shortened.