plotnine.stats.stat.stat

class plotnine.stats.stat.stat(mapping=None, data=None, **kwargs)[source]

Base class of all stats

static from_geom(geom)[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()[source]

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

stats should not override this method.

use_defaults(self, data)[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(self, data)[source]

Overide this to verify or adjust parameters

Parameters
datadataframe

Data

Returns
outdict

Parameters used by the stats.

setup_data(self, data)[source]

Overide to modify data before compute_layer is called

Parameters
datadataframe

Data

Returns
outdataframe

Data

finish_layer(self, data, params)[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, params, 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
datapanda.DataFrame

Data points for all objects in a layer.

paramsdict

Stat parameters

layoutplotnine.layout.Layout

Panel layout information

classmethod compute_panel(data, scales, **params)[source]

Calculate the stats of all the groups and 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

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

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

classmethod compute_group(data, scales, **params)[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(self)[source]

Make a layer that represents this stat

Returns
outlayer

Layer