plotnine.layer.layer¶
- class plotnine.layer.layer(geom: Geom, stat: Stat, *, mapping: aes, data: LayerDataLike | None, position: Position, inherit_aes: bool = True, show_legend: bool | None = None, raster: bool = False)[source]¶
Layer
When a
geom
orstat
is added to aggplot
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
- mapping
aes
, optional Aesthetic mappings.
- data
dataframe
, optional Data plotted in this layer. If
None
, the data from theggplot
object will be used.- positionposition, optional
Position object to adjust the geometries in this layer.
- inherit_aesbool, optional
If
True
inherit from the aesthetic mappings of theggplot
object. DefaultTrue
.- 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 isNone
.- 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
orstat
.- setup(plot: Ggplot)[source]¶
Prepare layer for the plot building
Give the layer access to the data, mapping and environment
- compute_aesthetics(plot: Ggplot)[source]¶
Return a dataframe where the columns match the aesthetic mappings
Transformations like 'factor(cyl)' and other expression evaluation are made in here
- compute_position(layout: Layout)[source]¶
Compute the position of each geometric object
This is in concert with the other objects in the panel depending on the position class of the geom
- draw(layout: Layout, coord: Coord)[source]¶
Draw geom
- Parameters:
- layout
Layout
Layout object created when the plot is getting built
- coord
coord
Type of coordinate axes
- layout