plotnine.stats.stat.stat

stat(mapping=None, data=None, **kwargs)

Base class of all stats

Attributes

Name Description
CREATES set() -> new empty set object
DEFAULT_AES dict() -> new empty dictionary
DEFAULT_PARAMS dict() -> new empty dictionary
NON_MISSING_AES set() -> new empty set object
REQUIRED_AES set() -> new empty set object

CREATES

CREATES : set[str] = set()

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

DEFAULT_AES

DEFAULT_AES : dict[str, Any] = aes(**self.DEFAULT_AES)

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

DEFAULT_PARAMS

DEFAULT_PARAMS : dict[str, Any] = {}

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

NON_MISSING_AES

NON_MISSING_AES : set[str] = set()

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

REQUIRED_AES

REQUIRED_AES : set[str] = set()

set() -> new empty set object set(iterable) -> new set object

Build an unordered collection of unique elements.

Methods

Name Description
aesthetics Return a set of all non-computed aesthetics for this stat.
compute_group Calculate statistics for the group
compute_layer Calculate statistics for this layers
compute_panel Calculate the statistics for all the groups
finish_layer Modify data after the aesthetics have been mapped
from_geom Return an instantiated stat object
setup_data Overide to modify data before compute_layer is called
setup_params Overide this to verify or adjust parameters
to_layer Make a layer that represents this stat
use_defaults Combine data with defaults and set aesthetics from parameters

aesthetics

aesthetics()

Return a set of all non-computed aesthetics for this stat.

stats should not override this method.

compute_group

compute_group(data, scales, **params)

Calculate statistics for the group

All stats should implement this method

Parameters

data : pd.DataFrame

Data for a group

scales : pos_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.

range_x = scales.x.dimension()
params : Any = {}

Parameters

compute_layer

compute_layer(data, params, layout)

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 : pd.DataFrame

Data points for all objects in a layer.

params : dict[str, Any]

Stat parameters

layout : Layout

Panel layout information

compute_panel

compute_panel(data, scales, **params)

Calculate the statistics for all the groups

Return the results in a single dataframe.

This is a default function that can be overriden by individual stats

Parameters

data : pd.DataFrame

data for the computing

scales : pos_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.

range_x = scales.x.dimension()
params : Any = {}

The parameters for the stat. It includes default values if user did not set a particular parameter.

finish_layer

finish_layer(data, params)

Modify data after the aesthetics have been mapped

This can be used by stats that require access to the mapped values of the computed aesthetics, part 3 as shown below.

1. stat computes and creates variables
2. variables mapped to aesthetics
3. stat sees and modifies data according to the
   aesthetic values

The default to is to do nothing.

Parameters

data : pd.DataFrame

Data for the layer

params : dict[str, Any]

Paremeters

Returns

data : pd.DataFrame

Modified data

from_geom

from_geom(geom)

Return an instantiated stat object

stats should not override this method.

Parameters

geom : geom

A geom object

Returns

stat

A stat object

Raises

PlotnineError if unable to create a stat.

setup_data

setup_data(data)

Overide to modify data before compute_layer is called

Parameters

data : pd.DataFrame

Data

Returns

out : pd.DataFrame

Data

setup_params

setup_params(data)

Overide this to verify or adjust parameters

Parameters

data : pd.DataFrame

Data

Returns

out : dict[str, Any]

Parameters used by the stats.

to_layer

to_layer()

Make a layer that represents this stat

Returns

out : layer

Layer

use_defaults

use_defaults(data)

Combine data with defaults and set aesthetics from parameters

stats should not override this method.

Parameters

data : pd.DataFrame

Data used for drawing the geom.

Returns

out : pd.DataFrame

Data used for drawing the geom.