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
geomgeom, optional

geom to used to draw this layer.

statstat, optional

stat used for the statistical transformation of data in this layer

datadataframe, optional

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

mappingaes, optional

Aesthetic mappings.

positionposition, optional

Position object to adjust the geometries in this layer.

inherit_aesbool, optional

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

show_legendbool 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
geomgeom

geom from which a layer will be created

Returns
outlayer

Layer that represents the specific geom.

generate_data(self, plot_data)[source]

Generate data to be used by this layer

Parameters
plot_datadataframe

ggplot object data

layer_mapping(self, mapping)[source]

Return the mappings that are active in this layer

Parameters
mappingaes

mappings in the ggplot call

Notes

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

compute_aesthetics(self, 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(self, layout)[source]

Compute & return statistics for this layer

map_statistic(self, plot)[source]

Mapping aesthetics to computed statistics

setup_data(self)[source]

Prepare/modify data for plotting

compute_position(self, layout)[source]

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

draw(self, layout, coord)[source]

Draw geom

Parameters
layoutLayout

Layout object created when the plot is getting built

coordcoord

Type of coordinate axes

use_defaults(self, data=None)[source]

Prepare/modify data for plotting

finish_statistics(self)[source]

Prepare/modify data for plotting