plotnine.geoms.geom.geom¶
- class plotnine.geoms.geom.geom(mapping: Aes | None = None, data: DataLike | None = None, **kwargs: Any)[source]¶
Base class of all Geoms
- mapping: Aes¶
mappings i.e.
aes(x='col1', fill='col2')
- data: DataLike¶
geom/layer specific dataframe
- static from_stat(stat: stat) geom [source]¶
Return an instantiated geom object
geoms should not override this method.
- classmethod aesthetics() set[str] [source]¶
Return all the aesthetics for this geom
geoms should not override this method.
- setup_data(data: DataFrame) DataFrame [source]¶
Modify the data before drawing takes place
This function is called before position adjustments are done. It is used by geoms to create the final aesthetics used for drawing. The base class method does nothing, geoms can override this method for two reasons:
The
stat
does not create all the aesthetics (usually position aesthetics) required for drawing thegeom
, but those aesthetics can be computed from the available data. For examplegeom_boxplot
andgeom_violin
.The
geom
inherits from anothergeom
(superclass) which does the drawing and the superclass requires certain aesthetics to be present in the data. For examplegeom_tile
andgeom_area
.
- use_defaults(data: pd.DataFrame, aes_modifiers: dict[str, Any]) pd.DataFrame [source]¶
Combine data with defaults and set aesthetics from parameters
geoms should not override this method.
- draw_layer(data: pd.DataFrame, layout: Layout, coord: Coord, **params: Any)[source]¶
Draw layer across all panels
geoms should not override this method.
- draw_panel(data: pd.DataFrame, panel_params: panel_view, coord: Coord, ax: Axes, **params: Any)[source]¶
Plot all groups
For efficiency, geoms that do not need to partition different groups before plotting should override this method and avoid the groupby.
- Parameters:
- data
dataframe
Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.
- panel_params
panel_view
The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Attributes are of interest to the geom are:
'panel_params.x.range' # tuple 'panel_params.y.range' # tuple
- coord
coord
Coordinate (e.g. coord_cartesian) system of the geom.
- ax
axes
Axes on which to plot.
- params
dict
Combined parameters for the geom and stat. Also includes the 'zorder'.
- data
- static draw_group(data: pd.DataFrame, panel_params: panel_view, coord: Coord, ax: Axes, **params: Any)[source]¶
Plot data belonging to a group.
- Parameters:
- data
dataframe
Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.
- panel_params
panel_view
The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Keys of interest to the geom are:
'x_range' # tuple 'y_range' # tuple
- coord
coord
Coordinate (e.g. coord_cartesian) system of the geom.
- ax
axes
Axes on which to plot.
- params
dict
Combined parameters for the geom and stat. Also includes the 'zorder'.
- data
- static draw_unit(data: pd.DataFrame, panel_params: panel_view, coord: Coord, ax: Axes, **params: Any)[source]¶
Plot data belonging to a unit.
A matplotlib plot function may require that an aethestic have a single unique value. e.g. linestyle='dashed' and not linestyle=['dashed', 'dotted', ...]. A single call to such a function can only plot lines with the same linestyle. However, if the plot we want has more than one line with different linestyles, we need to group the lines with the same linestyle and plot them as one unit. In this case, draw_group calls this function to do the plotting. For an example see
geom_point
.- Parameters:
- data
dataframe
Data to be plotted by this geom. This is the dataframe created in the plot_build pipeline.
- panel_params
panel_view
The scale information as may be required by the axes. At this point, that information is about ranges, ticks and labels. Keys of interest to the geom are:
'x_range' # tuple 'y_range' # tuple
In rare cases a geom may need access to the x or y scales. Those are available at:
'scales' # SimpleNamespace
- coord
coord
Coordinate (e.g. coord_cartesian) system of the geom.
- ax
axes
Axes on which to plot.
- params
dict
Combined parameters for the geom and stat. Also includes the 'zorder'.
- data
- handle_na(data: DataFrame) DataFrame [source]¶
Remove rows with NaN values
geoms that infer extra information from missing values should override this method. For example
geom_path
.Notes
Shows a warning if the any rows are removed and the na_rm parameter is False. It only takes into account the columns of the required aesthetics.