plotnine.stat_density
stat_density(=None,
mapping=None,
data*,
="density",
geom="stack",
position=False,
na_rm="gaussian",
kernel=1,
adjust=False,
trim=1024,
n=None,
gridsize="nrd0",
bw=3,
cut=(inf, inf),
clip**kwargs
)
Compute density estimate
Parameters
mapping : aes = None

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 after_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
'n' # Number of observations at a position
data : DataFrame = None

The data to be displayed in this layer. If
None
, the data from from theggplot()
call is used. If specified, it overrides the data from theggplot()
call. geom : str  geom = "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  position = "stack"

Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm : bool = False

If
False
, removes missing values with a warning. IfTrue
silently removes missing values. kernel : str = "gaussian"

Kernel used for density estimation. One of:
"biweight" "cosine" "cosine2" "epanechnikov" "gaussian" "triangular" "triweight" "uniform"
adjust : float = 1

An adjustment factor for the
bw
. Bandwidth becomesbw * adjust
. Adjustment of the bandwidth. trim : bool = 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. IfTrue
, each density is computed over the range of that group; this typically means the estimated x values will not lineup, and hence you won’t be able to stack density values. n : int = 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 = None

If gridsize is
None
,max(len(x), 50)
is used. bw : str  float = "nrd0"

The bandwidth to use, If a float is given, it is the bandwidth. The options are:
"nrd0" "normal_reference" "scott" "silverman"
nrd0
is a port ofstats::bw.nrd0
in R; it is eqiuvalent tosilverman
when there is more than 1 value in a group. cut : float = 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[float, float] = (inf, inf)

Values in
x
that are outside of the range given by clip are dropped. The number of values inx
is then shortened. **kwargs : Any = {}

Aesthetics or parameters used by the
geom
.