plotnine.layer.layer
layer(
geom,
stat,*,
mapping,
data,
position,=True,
inherit_aes=None,
show_legend=False
raster )
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
-
geom to used to draw this layer.
stat : stat
-
stat used for the statistical transformation of data in this layer
mapping : aes
-
Aesthetic mappings.
data : Optional[LayerDataLike]
-
Data plotted in this layer. If
None
, the data from theggplot
object will be used. position : position
-
Position object to adjust the geometries in this layer.
inherit_aes : bool = True
-
If
True
inherit from the aesthetic mappings of theggplot
object. show_legend : bool | dict[str, bool] | None = None
-
Whether to make up and show a legend for the mappings of this layer. If
None
then an automatic/good choice is made raster : bool = 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
.
Methods
Name | Description |
---|---|
compute_aesthetics | Return a dataframe where the columns match the aesthetic mappings |
compute_position | Compute the position of each geometric object |
compute_statistic | Compute & return statistics for this layer |
draw | Draw geom |
finish_statistics | Prepare/modify data for plotting |
from_geom | Create a layer given a geom |
map_statistic | Mapping aesthetics to computed statistics |
setup | Prepare layer for the plot building |
setup_data | Prepare/modify data for plotting |
use_defaults | Prepare/modify data for plotting |
compute_aesthetics
compute_aesthetics(plot)
Return a dataframe where the columns match the aesthetic mappings
Transformations like ‘factor(cyl)’ and other expression evaluation are made in here
compute_position
compute_position(layout)
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
compute_statistic
compute_statistic(layout)
Compute & return statistics for this layer
draw
draw(layout, coord)
Draw geom
Parameters
layout : Layout
-
Layout object created when the plot is getting built
coord : coord
-
Type of coordinate axes
finish_statistics
finish_statistics()
Prepare/modify data for plotting
from_geom
from_geom(geom)
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
.
map_statistic
map_statistic(plot)
Mapping aesthetics to computed statistics
setup
setup(plot)
Prepare layer for the plot building
Give the layer access to the data, mapping and environment
setup_data
setup_data()
Prepare/modify data for plotting
use_defaults
use_defaults(data, aes_modifiers)
Prepare/modify data for plotting