Stats¶
Point and Distribution Stats¶
stat_pointdensity¶
- class plotnine_extra.stat_pointdensity(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute density estimation for each point
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 color `after_stat(‘density’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "density" # Computed density at a point `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="point") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
package (Literal["statsmodels", "scipy", "sklearn"], default="statsmodels") – Package whose kernel density estimation to use.
kde_params (dict, default=None) – Keyword arguments to pass on to the kde class.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_pointThe default geom for this stat.
statsmodels.nonparametric.kde.KDEMultivariate,scipy.stats.gaussian_kde,sklearn.neighbors.KernelDensity- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'color': after_stat('density')}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'point', 'kde_params': None, 'na_rm': False, 'package': 'statsmodels', 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'density'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- setup_params(data)[source]¶
Override this to verify and/or adjust parameters
- Parameters:
data – Data
- Returns:
Parameters used by the stats.
- Return type:
out
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_mean¶
- class plotnine_extra.stat_mean(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute group mean points
Calculates the mean x and y coordinates for each group, producing a single centroid point per group.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="point") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_pointThe default geom for this stat.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'point', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_centroid¶
- class plotnine_extra.stat_centroid(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute the centroid of each group.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="point") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'point', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_midpoint¶
- class plotnine_extra.stat_midpoint(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute the midpoint of each group’s x / y range.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="point") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'point', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_chull¶
- class plotnine_extra.stat_chull(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute the convex hull of a set of points
Calculates the convex hull for each group and returns the subset of points that form the hull boundary.
{usage}
- Parameters:
{common_parameters}
mapping (aes | None)
data (DataLike | None)
kwargs (Any)
See also
plotnine.geom_pathThe default geom for this stat.
plotnine.geom_polygonAlternative geom for filled hulls.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'path', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_stars¶
- class plotnine_extra.stat_stars(mapping=None, data=None, **kwargs)[source]¶
Bases:
statDraw star segments from centroid to each point
Computes line segments from the group centroid (mean x, y) to each individual data point, creating a star-shaped pattern.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
Options for computed aesthetics
`python "xend" # x-coordinate of segment endpoint "yend" # y-coordinate of segment endpoint `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="segment") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_segmentThe default geom for this stat.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'segment', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'xend', 'yend'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_central_tendency¶
- class plotnine_extra.stat_central_tendency(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd central tendency measure to a density plot
Computes the mean, median, or mode of the data and returns coordinates for a vertical line at that position.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— x
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="line") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
type (str, default="mean") – Type of central tendency measure. One of
"mean","median", or"mode".**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_lineThe default geom for this stat.
- REQUIRED_AES = {'x'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'line', 'na_rm': False, 'position': 'identity', 'type': 'mean'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_conf_ellipse¶
- class plotnine_extra.stat_conf_ellipse(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute confidence ellipses around group barycenters
Draws a confidence ellipse based on the covariance structure of the bivariate data within each group.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="path") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
level (float, default=0.95) – Confidence level for the ellipse.
npoint (int, default=100) – Number of points used to draw the ellipse.
bary (bool, default=True) – If
True, compute the ellipse around the barycenter (mean). IfFalse, compute the ellipse around the data cloud.**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_pathThe default geom for this stat.
plotnine.geom_polygonAlternative geom for filled ellipses.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'bary': True, 'geom': 'path', 'level': 0.95, 'na_rm': False, 'npoint': 100, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_overlay_normal_density¶
- class plotnine_extra.stat_overlay_normal_density(mapping=None, data=None, **kwargs)[source]¶
Bases:
statOverlay a normal density curve on a histogram or density plot
Computes a theoretical normal distribution with the same mean and standard deviation as the data, useful for checking normality assumptions.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— x
The bold aesthetics are required.
Options for computed aesthetics
`python "density" # Normal density at each point `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="line") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
n (int, default=512) – Number of points at which to evaluate the density.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_lineThe default geom for this stat.
plotnine.stat_densityFor kernel density estimation.
- REQUIRED_AES = {'x'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'line', 'n': 512, 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'density'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_theodensity¶
- class plotnine_extra.stat_theodensity(mapping=None, data=None, **kwargs)[source]¶
Bases:
statFit a parametric distribution and return its density curve.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— x
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="line") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
distri (str, default
"norm") – Name of the distribution to fit. Anything in_DIST_MAP.n (int, default 256) – Number of grid points along the x range.
**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'x'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'distri': 'norm', 'geom': 'line', 'n': 256, 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_difference¶
- class plotnine_extra.stat_difference(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute the signed-difference ribbon between two y series.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— x ymax ymin
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="ribbon") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
**kwargs (Any) – Aesthetics or parameters used by the geom.
Notes
The
signaesthetic in the output frame can be mapped tofillto colour positive and negative differences differently:ggplot(d, aes("x", ymin="lo", ymax="hi")) + stat_difference(aes(fill="after_stat('sign')"))
- REQUIRED_AES = {'x', 'ymax', 'ymin'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'geom': 'ribbon', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'sign'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
pd.DataFrame
stat_funxy¶
- class plotnine_extra.stat_funxy(mapping=None, data=None, **kwargs)[source]¶
Bases:
statReduce each group’s x and y to scalar values via callables.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="point") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
funx (callable, default
numpy.mean()) – Reduction applied tox.funy (callable, default
numpy.mean()) – Reduction applied toy.**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'funx': <function mean>, 'funy': <function mean>, 'geom': 'point', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_rle¶
- class plotnine_extra.stat_rle(mapping=None, data=None, **kwargs)[source]¶
Bases:
statCompute run-length encoded segments of a categorical aes.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— label x
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="rect") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
align (str, default
"center") – Where to anchor the segment. One of"center","start"or"end".**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'label', 'x'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'align': 'center', 'geom': 'rect', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'end', 'run_id', 'run_length', 'runvalue', 'start', 'xmax', 'xmin'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_panel(data, scales)[source]¶
Calculate the statistics for all the groups
Return the results in a single dataframe.
This is a default function that can be overridden by individual stats
- Parameters:
data – data for the computing
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – The parameters for the stat. It includes default values if user did not set a particular parameter.
- Return type:
stat_rollingkernel¶
- class plotnine_extra.stat_rollingkernel(mapping=None, data=None, **kwargs)[source]¶
Bases:
statSmooth a series with a rolling kernel.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="line") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
bw (float, default 1.0) – Kernel bandwidth (in x units).
kernel (str, default
"gaussian") – One of"gaussian","triangular","epanechnikov"or"uniform".n (int, default 100) – Number of evaluation points along the x range.
**kwargs (Any) – Aesthetics or parameters used by the geom.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_PARAMS = {'bw': 1.0, 'geom': 'line', 'kernel': 'gaussian', 'n': 100, 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
Model and Test Annotation Stats¶
stat_cor¶
- class plotnine_extra.stat_cor(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd correlation coefficients with p-values to a scatter plot
Computes correlation coefficients (Pearson, Spearman, or Kendall) and formats them as text labels including p-values.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted correlation label "r" # Correlation coefficient "rr" # R-squared "p" # P-value `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
method (str, default="pearson") – Correlation method. One of
"pearson","spearman", or"kendall".alternative (str, default="two-sided") – Alternative hypothesis. One of
"two-sided","greater", or"less".label_x_npc (float or str, default="left") – Normalized x position for the label. Float in [0, 1] or one of
"left","center","right".label_y_npc (float or str, default="top") – Normalized y position for the label. Float in [0, 1] or one of
"top","center","bottom".r_accuracy (float, default=0.01) – Decimal accuracy for the correlation coefficient.
p_accuracy (float, default=0.001) – Decimal accuracy for the p-value.
label_sep (str, default=", ") – Separator between the correlation and p-value labels.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'label': after_stat('label')}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'alternative': 'two-sided', 'geom': 'text', 'label_sep': ', ', 'label_x_npc': 'left', 'label_y_npc': 'top', 'method': 'pearson', 'na_rm': False, 'p_accuracy': 0.001, 'position': 'identity', 'r_accuracy': 0.01}¶
Required parameters for the stat
- CREATES = {'label', 'p', 'r', 'rr'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_regline_equation¶
- class plotnine_extra.stat_regline_equation(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd regression line equation and R-squared to a plot
Fits a polynomial regression and formats the equation and goodness-of-fit statistics as a text label.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted equation label "eq" # Equation string "rr" # R-squared "adj_rr" # Adjusted R-squared "aic" # Akaike information criterion "bic" # Bayesian information criterion `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
formula (str, default="y ~ x") –
Regression formula. Supported forms:
"y ~ x": simple linear regression"y ~ poly(x, n)": polynomial of degree n
label_x_npc (float or str, default="left") – Normalized x position for the label.
label_y_npc (float or str, default="top") – Normalized y position for the label.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
plotnine.stat_smoothFor the regression line itself.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'label': after_stat('label')}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'formula': 'y ~ x', 'geom': 'text', 'label_x_npc': 'left', 'label_y_npc': 'top', 'na_rm': False, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'adj_rr', 'aic', 'bic', 'eq', 'label', 'rr'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_group(data, scales)[source]¶
Calculate statistics for the group
All stats should implement this method
- Parameters:
data – Data for a group
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – Parameters
- Return type:
stat_compare¶
- class plotnine_extra.stat_compare(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd group-mean comparison brackets to a plot.
Usage
- stat_compare(
mapping=None, data=None, *, geom=”bracket”, position=”identity”, na_rm=False, nudge=0, start=None, breaks=None, labels=None, cutoff=None, method=None, overall=False, ref_group=None, tip_length=0.02, parametric=False, correction=”none”, panel_indep=False, method_args=None, comparisons=None, step_increase=0.1, **kwargs
)
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Computed variables
`python "p" # raw p-value "q" # adjusted p-value "label" # display label (depends on breaks/labels/cutoff) "method" # test method name "xmin" # bracket left edge "xmax" # bracket right edge "y" # bracket top `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="bracket") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
nudge (float, default 0) – Vertical nudge of the bracket start position, as a fraction of the panel y-range.
start (float, optional) – Bracket start (top) position. Defaults to the maximum of the panel y-range.
breaks (sequence of float, optional) – Cutpoints for converting p-values to significance labels (e.g.
[0, 0.001, 0.01, 0.05, 1]).labels (sequence of str, optional) – Labels matching
breaks. Defaults to the"***"/"**"/"*"/"ns"family.cutoff (float, optional) – Hide labels with adjusted p-values above this value.
method (callable, optional) – Custom test function. Must accept two 1-D arrays (
x,y) and return an object with a.pvalueattribute (e.g. a scipyHypothesisResult). When omitted, the test is selected automatically based onparametricand the number of groups.overall (bool, default False) – If True, compare each group on the axis against the combined remaining groups (each x against “the rest”). Ignored when
ref_grouporcomparisonsis set.ref_group (str or int, optional) – Reference x-axis group; every other group is compared against this one.
tip_length (float, default 0.02) – Bracket tip length as a fraction of the panel y-range.
parametric (bool, default False) – If True, use parametric tests (t-test for 2 groups, one-way ANOVA for more). Otherwise use the non-parametric counterparts (Wilcoxon, Kruskal-Wallis).
correction (str, default
"none") – Multiple-testing correction method, one of"none","bonferroni","holm","hochberg","hommel","BH"/"fdr","BY".panel_indep (bool, default False) – If True, p-value correction is applied within each panel (matching ggpubr); otherwise it is applied at the layer level (across all panels).
method_args (dict, optional) – Additional keyword arguments forwarded to the test function.
comparisons (list of tuple, optional) – Explicit pairs of x-axis groups to compare, e.g.
[("compact", "midsize"), ("pickup", "suv")].step_increase (float, default 0.1) – Vertical spacing between consecutive brackets, as a fraction of the panel y-range.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine_extra.geoms.geom_bracketdefault
geom.plotnine_extra.stats.stat_pwcpairwise comparisons with manual configuration.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'label': after_stat('label')}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'breaks': None, 'comparisons': None, 'correction': 'none', 'cutoff': None, 'geom': 'bracket', 'labels': None, 'method': None, 'method_args': None, 'na_rm': False, 'nudge': 0, 'overall': False, 'panel_indep': False, 'parametric': False, 'position': 'identity', 'ref_group': None, 'start': None, 'step_increase': 0.1, 'tip_length': 0.02}¶
Required parameters for the stat
- CREATES = {'label', 'method', 'p', 'q', 'xmax', 'xmin', 'y'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_panel(data, scales)[source]¶
Calculate the statistics for all the groups
Return the results in a single dataframe.
This is a default function that can be overridden by individual stats
- Parameters:
data – data for the computing
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – The parameters for the stat. It includes default values if user did not set a particular parameter.
- Return type:
- compute_layer(data, layout)[source]¶
Calculate statistics for this layers
This is the top-most computation method for the stat. It does not do any computations, but it knows how to verify the data, partition it call the next computation method and merge results.
stats should not override this method.
- Parameters:
data – Data points for all objects in a layer.
layout – Panel layout information
- Return type:
stat_compare_means¶
- class plotnine_extra.stat_compare_means(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd mean comparison p-values to a plot
Performs statistical tests comparing groups and displays the results as text annotations. Supports t-test, Wilcoxon, ANOVA, and Kruskal-Wallis tests.
{usage}
- Parameters:
{common_parameters}
method (str, default="wilcox.test") – Statistical test method. One of
"t.test","wilcox.test","anova","kruskal.test".paired (bool, default=False) – Whether to perform a paired test.
comparisons (list of tuple, default=None) – List of group pairs to compare, e.g.
[("A", "B"), ("A", "C")]. IfNone, performs a global test across all groups.ref_group (str, default=None) – Reference group for pairwise comparisons. Each group is compared against this reference.
hide_ns (bool, default=False) – If
True, hide non-significant results.label (str, default="p.format") – Label format. One of
"p.format","p.signif","p.format.signif".label_x_npc (float or str, default="center") – Normalized x position for global test label.
label_y_npc (float or str, default="top") – Normalized y position for global test label.
p_digits (int, default=3) – Number of digits for p-value formatting.
step_increase (float, default=0.1) – Fraction of y-range to step between comparison brackets.
See also
plotnine.geom_textThe default geom for this stat.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'label': after_stat('label'), 'wid': None}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'comparisons': None, 'geom': 'text', 'hide_ns': False, 'label': 'p.format', 'label_x_npc': 'center', 'label_y_npc': 'top', 'method': 'wilcox.test', 'na_rm': False, 'p_digits': 3, 'paired': False, 'position': 'identity', 'ref_group': None, 'step_increase': 0.1, 'wid': None}¶
Required parameters for the stat
- CREATES = {'label', 'method', 'p', 'p_signif'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_panel(data, scales)[source]¶
Calculate the statistics for all the groups
Return the results in a single dataframe.
This is a default function that can be overridden by individual stats
- Parameters:
data – data for the computing
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – The parameters for the stat. It includes default values if user did not set a particular parameter.
- Return type:
stat_anova_test¶
- class plotnine_extra.stat_anova_test(mapping=None, data=None, **kwargs)[source]¶
Bases:
_base_stat_testAdd ANOVA test p-values to a plot
Performs one-way ANOVA and displays the result as a text annotation including F-statistic, degrees of freedom, and p-value.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted test result label "p" # P-value "p_signif" # Significance symbol "f" # F-statistic "df" # Numerator degrees of freedom "df_residual" # Denominator degrees of freedom "effect_size" # Effect size (eta-squared) "method" # Name of the test `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
method (str, default="one_way") – ANOVA method. Currently supports
"one_way".effect_size (str, default="ges") – Type of effect size. One of
"ges"(generalized eta-squared) or"pes"(partial eta-squared).label_x_npc (float or str, default="center") – Normalized x position for the label.
label_y_npc (float or str, default="top") – Normalized y position for the label.
p_digits (int, default=3) – Number of digits for p-value formatting.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
- DEFAULT_PARAMS = {'effect_size': 'ges', 'geom': 'text', 'label_x_npc': 'center', 'label_y_npc': 'top', 'method': 'one_way', 'na_rm': False, 'p_digits': 3, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'df', 'df_residual', 'effect_size', 'f', 'label', 'method', 'p', 'p_signif'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
stat_kruskal_test¶
- class plotnine_extra.stat_kruskal_test(mapping=None, data=None, **kwargs)[source]¶
Bases:
_base_stat_testAdd Kruskal-Wallis test p-values to a plot
Performs a Kruskal-Wallis rank sum test and displays the result as a text annotation. This is a non-parametric alternative to one-way ANOVA.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted test result label "p" # P-value "p_signif" # Significance symbol "statistic" # Test statistic (H) "df" # Degrees of freedom "method" # Name of the test `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
label_x_npc (float or str, default="center") – Normalized x position for the label.
label_y_npc (float or str, default="top") – Normalized y position for the label.
p_digits (int, default=3) – Number of digits for p-value formatting.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
- DEFAULT_PARAMS = {'geom': 'text', 'label_x_npc': 'center', 'label_y_npc': 'top', 'na_rm': False, 'p_digits': 3, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'df', 'label', 'method', 'p', 'p_signif', 'statistic'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
stat_welch_anova_test¶
- class plotnine_extra.stat_welch_anova_test(mapping=None, data=None, **kwargs)[source]¶
Bases:
_base_stat_testAdd Welch’s ANOVA test p-values to a plot
Performs Welch’s one-way ANOVA, which does not assume equal variances across groups, and displays the result as a text annotation.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted test result label "p" # P-value "p_signif" # Significance symbol "f" # F-statistic "df1" # Numerator degrees of freedom "df2" # Denominator degrees of freedom "method" # Name of the test `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
label_x_npc (float or str, default="center") – Normalized x position for the label.
label_y_npc (float or str, default="top") – Normalized y position for the label.
p_digits (int, default=3) – Number of digits for p-value formatting.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
- DEFAULT_PARAMS = {'geom': 'text', 'label_x_npc': 'center', 'label_y_npc': 'top', 'na_rm': False, 'p_digits': 3, 'position': 'identity'}¶
Required parameters for the stat
- CREATES = {'df1', 'df2', 'f', 'label', 'method', 'p', 'p_signif'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
stat_friedman_test¶
- class plotnine_extra.stat_friedman_test(mapping=None, data=None, **kwargs)[source]¶
Bases:
_base_stat_testAdd Friedman test p-values to a plot
Performs the Friedman test, a non-parametric test for repeated measures (alternative to repeated-measures ANOVA), and displays the result as a text annotation.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 label `after_stat(‘label’)`{.py} wid `None`{.py}
The bold aesthetics are required.
Options for computed aesthetics
`python "label" # Formatted test result label "p" # P-value "p_signif" # Significance symbol "statistic" # Test statistic (chi-squared) "df" # Degrees of freedom "method" # Name of the test `data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
geom (str | geom, default="text") – 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, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
wid (str, default=None) – Column name identifying subjects/individuals. Required for reshaping the data into the wide format needed by the Friedman test.
label_x_npc (float or str, default="center") – Normalized x position for the label.
label_y_npc (float or str, default="top") – Normalized y position for the label.
p_digits (int, default=3) – Number of digits for p-value formatting.
**kwargs (Any) – Aesthetics or parameters used by the geom.
See also
plotnine.geom_textThe default geom for this stat.
- DEFAULT_PARAMS = {'geom': 'text', 'label_x_npc': 'center', 'label_y_npc': 'top', 'na_rm': False, 'p_digits': 3, 'position': 'identity', 'wid': None}¶
Required parameters for the stat
- DEFAULT_AES = {'label': after_stat('label'), 'wid': None}¶
Default aesthetics for the stat
- CREATES = {'df', 'label', 'method', 'p', 'p_signif', 'statistic'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
stat_pvalue_manual¶
- plotnine_extra.stat_pvalue_manual(data, label=None, y_position=None, xmin='group1', xmax='group2', tip_length=0.02, step_increase=0.05, step_group_by=None, hide_ns=False, remove_bracket=False, bracket_nudge_y=0, label_size=8, vjust=-0.5, color='black', x_levels=None, **kwargs)[source]¶
Add manually specified p-values to a plot with brackets.
- Parameters:
data (DataFrame) – Data frame containing at minimum columns for group positions and p-values. Expected columns include
group1,group2, andporp.adj.label (str, optional) – Column name to use for the label, or
"p.signif"to auto-convert p-values to significance symbols. IfNone, uses"p"column formatted.y_position (str or float, optional) – Column name for y-coordinates of brackets, or a single float value. If
None, uses"y.position"or"y_position"column.xmin (str, default="group1") – Column name for the left x-coordinate of brackets.
xmax (str, default="group2") – Column name for the right x-coordinate of brackets.
tip_length (float, default=0.02) – Length of bracket tips as fraction of y range.
step_increase (float, default=0.05) – Step increase between brackets as fraction of y range.
step_group_by (str, optional) – Column to group comparisons for stacking.
hide_ns (bool, default=False) – If
True, hide non-significant results.remove_bracket (bool, default=False) – If
True, show only labels without brackets.bracket_nudge_y (float, default=0) – Vertical nudge for brackets.
label_size (float, default=8) – Font size for labels.
vjust (float, default=-0.5) – Vertical justification of labels.
color (str, default="black") – Color for brackets and labels.
**kwargs (Any) – Additional aesthetic parameters.
**kwargs
- Returns:
List of plotnine layers (geom_segment + geom_text) that can be added to a ggplot.
- Return type:
stat_pwc¶
- class plotnine_extra.stat_pwc(mapping=None, data=None, **kwargs)[source]¶
Bases:
statAdd pairwise comparison p-values to a plot
Performs pairwise statistical tests between groups and displays the results as bracket annotations. Supports t-test and Wilcoxon (Mann-Whitney U) tests. The default geom is
geom_bracket.{usage}
- Parameters:
{common_parameters}
method (str, default="wilcox.test") – Statistical test method for pairwise comparisons. One of
"t.test"or"wilcox.test".paired (bool, default=False) – Whether to perform a paired test.
ref_group (str or int, default=None) – Reference group for pairwise comparisons. Each group is compared against this reference. If
None, all pairwise combinations are tested.comparisons (list of tuple, default=None) – Explicit list of group pairs to compare, e.g.
[("A", "B"), ("A", "C")]. Overridesref_groupwhen specified.p_adjust_method (str, default="holm") – Method for adjusting p-values for multiple comparisons. One of
"bonferroni","holm","hochberg","hommel","BH","BY","fdr","none".label (str, default="p.format") – Label format. One of
"p.format","p.signif","p.adj.format","p.adj.signif","p.format.signif","p.adj.format.signif".hide_ns (bool, default=False) – If
True, hide non-significant comparisons.p_digits (int, default=3) – Number of digits for p-value formatting.
step_increase (float, default=0.12) – Fraction of y-range to step between comparison brackets to minimize overlap.
bracket_nudge_y (float, default=0.05) – Vertical offset for brackets as a fraction of the y-range.
tip_length (float, default=0.03) – Length of bracket tips as a fraction of y-range, passed to
geom_bracket.bracket_shorten (float, default=0) – Amount to shorten brackets from each end.
remove_bracket (bool, default=False) – If
True, remove brackets and only show labels (usesgeom_textinstead ofgeom_bracket).
See also
plotnine_extra.geom_bracketThe default geom for this stat.
plotnine_extra.stat_compare_meansMean comparison with support for global tests.
- REQUIRED_AES = {'x', 'y'}¶
Required aesthetics for the stat
- DEFAULT_AES = {'label': after_stat('label'), 'wid': None}¶
Default aesthetics for the stat
- DEFAULT_PARAMS = {'bracket_nudge_y': 0.05, 'bracket_shorten': 0, 'comparisons': None, 'geom': 'bracket', 'hide_ns': False, 'label': 'p.format', 'method': 'wilcox.test', 'na_rm': False, 'p_adjust_method': 'holm', 'p_digits': 3, 'paired': False, 'position': 'identity', 'ref_group': None, 'remove_bracket': False, 'step_increase': 0.12, 'tip_length': 0.03, 'wid': None}¶
Required parameters for the stat
- CREATES = {'group1', 'group2', 'label', 'method', 'p', 'p_adj', 'p_adj_signif', 'p_signif', 'xmax', 'xmin', 'y'}¶
Stats may modify existing columns or create extra columns.
Any extra columns that may be created by the stat should be specified in this set see: stat_bin
Documentation for the aesthetics. It ie added under the documentation for mapping parameter. Use {aesthetics_table} placeholder to insert a table for all the aesthetics and their default values.
- compute_panel(data, scales)[source]¶
Calculate the statistics for all the groups
Return the results in a single dataframe.
This is a default function that can be overridden by individual stats
- Parameters:
data – data for the computing
scales –
x (
scales.x) and y (scales.y) scale objects. The most likely reason to use scale information is to find out the physical size of a scale. e.g.`python range_x = scales.x.dimension() `params – The parameters for the stat. It includes default values if user did not set a particular parameter.
P-value Helpers¶
format_p_value¶
- plotnine_extra.format_p_value(p, digits=3, style='default', accuracy=None, leading_zero=True)[source]¶
Format a p-value for display.
- Parameters:
p (float) – P-value to format.
digits (int, default 3) – Number of decimal digits (default style only).
style (str, default
"default") – Name of the format style. Seelist_p_format_styles().accuracy (float, optional) – If provided, p-values smaller than this threshold are rendered as
"p < <accuracy>".leading_zero (bool, default True) – Whether to keep the leading
0..
- Return type:
create_p_label¶
list_p_format_styles¶
get_p_format_style¶
ggadjust_pvalue¶
- plotnine_extra.ggadjust_pvalue(plot, p_adjust_method='holm', label=None)[source]¶
Re-adjust p-values displayed on an existing plot.
Walks
plot.layersand updates thep_adjust_methodparameter of anystat_pwc/stat_compare_means/stat_pvalue_manuallayer in place. The plot is then returned for chaining.- Parameters:
plot (ggplot) – The plot to mutate.
p_adjust_method (str, default
"holm") – New adjustment method. One of"bonferroni","holm","hochberg","hommel","BH","BY","fdr","none".label (str, optional) – New label format (e.g.
"p.adj.signif").