plotnine.stats.stat.stat

class plotnine.stats.stat.stat(mapping: Aes | None = None, data: DataLike | None = None, **kwargs: Any)[source]

Base class of all stats

static from_geom(geom: Geom) stat[source]

Return an instantiated stat object

stats should not override this method.

Parameters:
geomgeom

geom

Returns:
outstat

A stat object

Raises:
PlotnineError if unable to create a stat.
classmethod aesthetics() set[str][source]

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

stats should not override this method.

use_defaults(data: DataFrame) DataFrame[source]

Combine data with defaults and set aesthetics from parameters

stats should not override this method.

Parameters:
datadataframe

Data used for drawing the geom.

Returns:
outdataframe

Data used for drawing the geom.

setup_params(data: pd.DataFrame) dict[str, Any][source]

Overide this to verify or adjust parameters

Parameters:
datadataframe

Data

Returns:
outdict

Parameters used by the stats.

setup_data(data: DataFrame) DataFrame[source]

Overide to modify data before compute_layer is called

Parameters:
datadataframe

Data

Returns:
outdataframe

Data

finish_layer(data: pd.DataFrame, params: dict[str, Any]) pd.DataFrame[source]

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:
datadataframe

Data for the layer

paramsdict

Paremeters

Returns:
datadataframe

Modified data

classmethod compute_layer(data: pd.DataFrame, params: dict[str, Any], layout: Layout) pd.DataFrame[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:
datapanda.DataFrame

Data points for all objects in a layer.

paramsdict

Stat parameters

layoutplotnine.layout.Layout

Panel layout information

classmethod compute_panel(data: pd.DataFrame, scales: pos_scales, **params: Any)[source]

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:
datadataframe

data for the computing

scalesdataclass

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()
paramsdict

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

classmethod compute_group(data: pd.DataFrame, scales: pos_scales, **params: Any) pd.DataFrame[source]

Calculate statistics for the group

All stats should implement this method

Parameters:
datadataframe

Data for a group

scalestypes.SimpleNamespace

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()
paramsdict

Parameters

to_layer()[source]

Make a layer that represents this stat

Returns:
outlayer

Layer