plotnine.layer.layer

class plotnine.layer.layer(geom=None, stat=None, data=None, mapping=None, position=None, inherit_aes=True, show_legend=None)[source]

Layer

When a geom or stat is added to a ggplot object, it creates a single layer. This class is a representation of that layer.

Parameters:
geom : geom, optional

geom to used to draw this layer.

stat : stat, optional

stat used for the statistical transformation of data in this layer

data : dataframe, optional

Data plotted in this layer. If None, the data from the ggplot object will be used.

mapping : aes, optional

Aesthetic mappings.

position : position, optional

Position object to adjust the geometries in this layer.

inherit_aes : bool, optional

If True inherit from the aesthetic mappings of the ggplot object. Default True.

show_legend : bool or None, optional

Whether to make up and show a legend for the mappings of this layer. If None then an automatic/good choice is made. Default is None.

Notes

There is no benefit to manually creating a layer. You should always use a geom or stat.

static from_geom(geom)[source]

Create a layer given a geom

Parameters:
geom : geom

geom from which a layer will be created

Returns:
out : layer

Layer that represents the specific geom.

generate_data(plot_data)[source]

Generate data to be used by this layer

Parameters:
plot_data : dataframe

ggplot object data

layer_mapping(mapping)[source]

Return the mappings that are active in this layer

Parameters:
mapping : aes

mappings in the ggplot call

Notes

Once computed the layer mappings are also stored in self._active_mapping

compute_aesthetics(plot)[source]

Return a dataframe where the columns match the aesthetic mappings.

Transformations like 'factor(cyl)' and other expression evaluation are made in here

compute_statistic(layout)[source]

Compute & return statistics for this layer

map_statistic(plot)[source]

Mapping aesthetics to computed statistics

setup_data()[source]

Prepare/modify data for plotting

compute_position(layout)[source]

Compute the position of each geometric object in concert with the other objects in the panel

draw(layout, coord)[source]

Draw geom

Parameters:
layout : Layout

Layout object created when the plot is getting built

coord : coord

Type of coordinate axes

use_defaults(data=None)[source]

Prepare/modify data for plotting

finish_statistics()[source]

Prepare/modify data for plotting