Composition¶
Compose¶
- class plotnine_extra.Compose(items)[source]¶
Bases:
objectBase class for those that create plot compositions
As a user, you will never directly work with this class, except through the operators that it makes possible. The operators are of two kinds:
### 1. Composing Operators
The combine plots or compositions into a single composition. Both operands are either a plot or a composition.
/
- : Arrange operands vertically.
Powered by the subclass [](~plotnine_extra.composition.Stack).
|
- : Arrange operands side by side.
Powered by the subclass [](~plotnine_extra.composition.Beside).
-
- : Arrange operands side by side _and_ at the same nesting
level. Also powered by the subclass [](~plotnine_extra.composition.Beside).
+
- : Arrange operands in a 2D grid.
Powered by the subclass [](~plotnine_extra.composition.Wrap).
### 2. Plot Modifying Operators
The modify all or some of the plots in a composition. The left operand is a composition and the right operand is a _plotaddable_; any object that can be added to a ggplot object e.g. _geoms_, _stats_, _themes_, _facets_, … .
&
: Add right hand side to all plots in the composition.
*
- : Add right hand side to all plots in the top-most nesting
level of the composition.
+
: Add right hand side to the last plot in the composition.
See also
plotnine_extra.composition.Beside,plotnine_extra.composition.Stack,plotnine_extra.composition.Wrap,plotnine_extra.composition.plot_spacer- figure: Figure¶
- property layout: plot_layout¶
The plot_layout of this composition
- property annotation: plot_annotation¶
The plot_annotation of this composition
- property theme: plotnine.theme¶
Theme for this composition
This is the default theme plus combined with theme from the annotation.
- property last_plot: ggplot¶
Last plot added to the composition
- draw(*, show=False)[source]¶
Render the arranged plots
- Parameters:
show (bool) – Whether to show the plot.
- Returns:
Matplotlib figure
- Return type:
Figure
- save(filename, format=None, dpi=None, **kwargs)[source]¶
Save a composition as an image file
- Parameters:
filename (str | Path | BytesIO) – File name to write the plot to.
format (str | None) – Image format to use, automatically extracted from file name extension.
dpi (int | None) – DPI to use for raster graphics. If None, defaults to using the dpi of theme to the first plot.
**kwargs – These are ignored. Here to “softly” match the API of ggplot.save().
Beside¶
- class plotnine_extra.Beside(items)[source]¶
Bases:
ComposePlace plots or compositions side by side
Usage
plot | plot plot | composition composition | plot composition | composition
Typically, you will use this class through the | operator.
See also
plotnine_extra.composition.Stack,plotnine_extra.composition.Wrap,plotnine_extra.composition.plot_spacer,plotnine_extra.composition.Compose
Stack¶
- class plotnine_extra.Stack(items)[source]¶
Bases:
ComposePlace plots or compositions on top of each other
Usage
plot / plot plot / composition composition / plot composition / composition
Typically, you will use this class through the / operator.
See also
plotnine_extra.composition.Beside,plotnine_extra.composition.Wrap,plotnine_extra.composition.plot_spacer,plotnine_extra.composition.Compose
Wrap¶
- class plotnine_extra.Wrap(items)[source]¶
Bases:
ComposeWrap plots or compositions into a grid
Usage
plot + plot plot + composition composition + plot composition + composition
Typically, you will use this class through the + operator.
- Parameters:
See also
plotnine_extra.composition.Beside,plotnine_extra.composition.Stack,plotnine_extra.composition.plot_spacer,plotnine_extra.composition.Compose
plot_layout¶
plot_annotation¶
- plotnine_extra.plot_annotation(*, title=None, subtitle=None, caption=None, footer=None, theme=<factory>)[source]¶
Annotate a composition
This applies to only the top-level composition. When a composition with an annotation is added to larger composition, the annotation of the sub-composition becomes irrelevant.
- Parameters:
title (str | None)
subtitle (str | None)
caption (str | None)
footer (str | None)
theme (plotnine.theme)
- Return type:
None
plot_spacer¶
- plotnine_extra.plot_spacer(fill=None)[source]¶
Blank area as wide or as tall as a plot
- Parameters:
fill (str | tuple[float, float, float] | tuple[float, float, float, float] | None) –
Background color. The default is a transparent area, but it can be changed through this parameter.
The color can also be modified by adding a [](~plotnine.theme) and setting the [](~plotnine.themes.themeable.plot_background).
See also
plotnine_extra.composition.Beside,plotnine_extra.composition.Stack,plotnine_extra.composition.Compose