plotnine.geoms.geom.geom

class plotnine.geoms.geom.geom(*args, **kwargs)[source]

Base class of all Geoms

DEFAULT_AES = {}

Default aesthetics for the geom

REQUIRED_AES = {}

Required aesthetics for the geom

NON_MISSING_AES = {}

Required aesthetics for the geom

DEFAULT_PARAMS = {}

Required parameters for the geom

mapping = None

mappings i.e. aes(x='col1', fill='col2')

data = None

geom/layer specific dataframe

static from_stat(stat)[source]

Return an instantiated geom object

geoms should not override this method.

Parameters:
stat : stat

stat

Returns:
out : geom

A geom object

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

Return all the aesthetics for this geom

geoms should not override this method.

setup_data(data)[source]

Modify the data before drawing takes place

This function is called before position adjustments are done. It is used by geoms to create the final aesthetics used for drawing. The base class method does nothing, geoms can override this method for two reasons:

  1. The stat does not create all the aesthetics (usually position aesthetics) required for drawing the geom, but those aesthetics can be computed from the available data. For example geom_boxplot and geom_violin.
  2. The geom inherits from another geom (superclass) which does the drawing and the superclass requires certain aesthetics to be present in the data. For example geom_tile and geom_area.
Parameters:
data : dataframe

Data used for drawing the geom.

Returns:
out : dataframe

Data used for drawing the geom.

use_defaults(data)[source]

Combine data with defaults and set aesthetics from parameters

geoms should not override this method.

Parameters:
data : dataframe

Data used for drawing the geom.

Returns:
out : dataframe

Data used for drawing the geom.

draw_layer(data, layout, coord, **params)[source]

Draw layer across all panels

geoms should not override this method.

Parameters:
data : DataFrame

DataFrame specific for this layer

layout : Lanel

Layout object created when the plot is getting built

coord : coord

Type of coordinate axes

params : dict

Combined geom and stat parameters. Also includes the stacking order of the layer in the plot (zorder)

draw_panel(data, panel_params, coord, ax, **params)[source]

Plot all groups

For effeciency, geoms that do not need to partition different groups before plotting should override this method and avoid the groupby.

Parameters:
data : dataframe

Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.

scales : dict

The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Keys of interest to the geom are:

'x_range'  # tuple
'y_range'  # tuple
coord : coord

Coordinate (e.g. coord_cartesian) system of the geom.

ax : axes

Axes on which to plot.

params : dict

Combined parameters for the geom and stat. Also includes the 'zorder'.

static draw_group(data, panel_params, coord, ax, **params)[source]

Plot data belonging to a group.

Parameters:
data : dataframe

Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.

scales : dict

The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Keys of interest to the geom are:

'x_range'  # tuple
'y_range'  # tuple
coord : coord

Coordinate (e.g. coord_cartesian) system of the geom.

ax : axes

Axes on which to plot.

params : dict

Combined parameters for the geom and stat. Also includes the 'zorder'.

static draw_unit(data, panel_params, coord, ax, **params)[source]

Plot data belonging to a unit.

A matplotlib plot function may require that an aethestic have a single unique value. e.g. linestyle='dashed' and not linestyle=['dashed', 'dotted', ...]. A single call to such a function can only plot lines with the same linestyle. However, if the plot we want has more than one line with different linestyles, we need to group the lines with the same linestyle and plot them as one unit. In this case, draw_group calls this function to do the plotting. For an example see geom_point.

Parameters:
data : dataframe

Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.

scales : dict

The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Keys of interest to the geom are:

'x_range'  # tuple
'y_range'  # tuple
coord : coord

Coordinate (e.g. coord_cartesian) system of the geom.

ax : axes

Axes on which to plot.

params : dict

Combined parameters for the geom and stat. Also includes the 'zorder'.

handle_na(data)[source]

Remove rows with NaN values

geoms that infer extra information from missing values should override this method. For example geom_path.

Parameters:
data : dataframe

Data

Returns:
out : dataframe

Data without the NaNs.

Notes

Shows a warning if the any rows are removed and the na_rm parameter is False. It only takes into account the columns of the required aesthetics.