plotnine.stats.stat_ydensity¶
- class plotnine.stats.stat_ydensity(mapping: Aes | None = None, data: DataLike | None = None, **kwargs: Any)[source]¶
Density estimate
Usage
stat_ydensity(mapping=None, data=None, geom='violin', position='dodge', na_rm=False, n=1024, trim=True, scale='area', bw='nrd0', kernel='gaussian', adjust=1, **kwargs)
Only the
mapping
anddata
can be positional, the rest must be keyword arguments.**kwargs
can be aesthetics (or parameters) used by thegeom
.- Parameters:
- mapping
aes
, optional Aesthetic mappings created with
aes()
. If specified andinherit.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
weight
None
The bold aesthetics are required.
Options for computed aesthetics
'width' # Maximum width of density, [0, 1] range. 'violinwidth' # Shape of the violin
Calculated aesthetics are accessed using the after_stat function. e.g.
after_stat('width')
.- data
dataframe
, optional 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
or geom, optional (default:geom_violin
) 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:position_dodge
) Position adjustment. If it is a string, it must be registered and known to Plotnine.
- na_rmbool, optional (default:
False
) If
False
, removes missing values with a warning. IfTrue
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 becomesbw * adjust
. Adjustment of the bandwidth.- trimbool, 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. IfTrue
, 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.
- bw
str
orfloat
, optional (default: 'nrd0') The bandwidth to use, If a float is given, it is the bandwidth. The
str
choices are:'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.- scale(default:
area
) How to scale the violins. The options are:
'area' # all violins have the same area, before # trimming the tails. 'count' # areas are scaled proportionally to the number # of observations. 'width' # all violins have the same maximum width.
- mapping