plotnine.layer.layer

class plotnine.layer.layer(geom=None, stat=None, data=None, mapping=None, position=None, inherit_aes=True, show_legend=None, raster=False)[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.

rasterbool, optional (default: False)

If True, draw onto this layer a raster (bitmap) object even if the final image format is vector.

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.

make_layer_data(plot_data)[source]

Generate data to be used by this layer

Parameters
plot_datadataframe

ggplot object data

make_layer_mapping(plot_mapping)[source]

Create the aesthetic mappings to be used by this layer

Parameters
plot_mappingaes

ggplot object mapping

make_layer_environments(plot_environment)[source]

Create the aesthetic mappings to be used by this layer

Parameters
plot_environmentEvalEnvironment

Namespace in which to execute aesthetic expressions.

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
layoutLayout

Layout object created when the plot is getting built

coordcoord

Type of coordinate axes

use_defaults(data=None, aes_modifiers=None)[source]

Prepare/modify data for plotting

Parameters
datadataframe, optional

Data

aes_modifiersdict

Expression to evaluate and replace aesthetics in the data.

finish_statistics()[source]

Prepare/modify data for plotting