plotnine.stats.stat.stat

class plotnine.stats.stat.stat(*args, **kwargs)[source]

Base class of all stats

static from_geom(geom)[source]

Return an instantiated stat object

stats should not override this method.

Parameters:
geom : geom

geom

Returns:
out : stat

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

Combine data with defaults and set aesthetics from parameters

stats should not override this method.

Parameters:
data : dataframe

Data used for drawing the geom.

Returns:
out : dataframe

Data used for drawing the geom.

setup_params(data)[source]

Overide this to verify or adjust parameters

Parameters:
data : dataframe

Data

Returns:
out : dict

Parameters used by the stats.

setup_data(data)[source]

Overide to modify data before compute_layer is called

Parameters:
data : dataframe

Data

Returns:
out : dataframe

Data

finish_layer(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:
data : dataframe

Data for the layer

params : dict

Paremeters

Returns:
data : dataframe

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:
data : panda.DataFrame

Data points for all objects in a layer.

params : dict

Stat parameters

layout : plotnine.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:
data : dataframe

data for the computing

scales : types.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()
params : dict

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:
data : dataframe

Data for a group

scales : types.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()
params : dict

Parameters