from plotnine import ggplot, aes, geom_line
import pandas as pd
import numpy as np
# Load the Metabric dataset from the URL into a DataFrame
= pd.read_csv("https://zenodo.org/record/6450144/files/metabric_clinical_and_expression_data.csv") metabric
Visualizing Data
Overview
In this section, you’ll learn how to use plotnine
in Python to create data visualizations using the grammar of graphics. The grammar of graphics is a high-level framework that simplifies the process of creating plots, allowing you to focus on meaningful and aesthetically pleasing visualizations rather than low-level details.
Several Python packages implement a grammar of graphics, but this tutorial focuses on plotnine
due to its maturity and ease of use. plotnine
is inspired by ggplot2
from the R programming language, making it a familiar tool for those with an R background. Essentially, plotnine
serves as the Python equivalent of ggplot2
.
The plotnine
package streamlines plot creation using data frames by providing an intuitive interface to define variables, customize displays, and modify visual attributes. This approach allows you to adapt to changes in the data or switch between plot types with minimal code modifications, resulting in high-quality, publication-ready plots with little manual adjustment.
Like ggplot2
, plotnine
prefers data in the “long” format, where each variable occupies a column, and each observation corresponds to a row. Organizing data this way enhances efficiency when generating complex and varied visualizations, making the plotting process more consistent and flexible.
We will be using an extended version of the Metabric dataset in which columns have been added for the mRNA expression values for selected genes, including estrogen receptor alpha (ESR1), progesterone receptor (PGR), GATA3 and FOXA1.
Building a Basic Plot
The construction of ggplot graphics is incremental, allowing for the addition of new elements in layers. This approach grants users extensive flexibility and customization options, enabling the creation of tailored plots to suit specific needs.
To build a ggplot using plotnine
, the following templates can be used for different types of plots. This will be consistently used in subsequent examples.
Three things are required for a ggplot:
1. The data
We first specify the data frame that contains the relevant data to create a plot. Here we are sending the metabric dataset to the ggplot()
function.
import plotnine
= (6, 4)
plotnine.options.figure_size = 50 plotnine.options.dpi
# render plot background
= metabric).draw() ggplot(data
This command results in an empty gray panel. We must specify how various columns of the data frame should be depicted in the plot.
2. Aesthetics aes()
Next, we specify the columns in the data we want to map to visual properties (called aesthetics or aes
function). e.g. the columns for x values, y values and colours.
Since we are interested in generating a scatter plot, each point will have an x and a y coordinate. Therefore, we need to specify the x-axis to represent the year and y-axis to represent the count.
= metabric, mapping = aes(x = "GATA3", y = "ESR1")).draw() ggplot(data
This results in a plot which includes the grid lines, the variables and the scales for x and y axes. However, the plot is empty or lacks data points.
3. Geometric Representation geom_()
Finally, we specify the type of plot (the geom). There are different types of geoms:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The range of geoms available in plotnine
package can be obtained by navigating to the help page of geoms
package in the plotnine
package as follows:
import plotnine
help(plotnine.geoms)
Help on package plotnine.geoms in plotnine:
NAME
plotnine.geoms - Plotting objects
PACKAGE CONTENTS
annotate
annotation_logticks
annotation_stripes
geom
geom_abline
geom_area
geom_bar
geom_bin_2d
geom_blank
geom_boxplot
geom_col
geom_count
geom_crossbar
geom_density
geom_density_2d
geom_dotplot
geom_errorbar
geom_errorbarh
geom_freqpoly
geom_histogram
geom_hline
geom_jitter
geom_label
geom_line
geom_linerange
geom_map
geom_path
geom_point
geom_pointdensity
geom_pointrange
geom_polygon
geom_qq
geom_qq_line
geom_quantile
geom_raster
geom_rect
geom_ribbon
geom_rug
geom_segment
geom_sina
geom_smooth
geom_spoke
geom_step
geom_text
geom_tile
geom_violin
geom_vline
CLASSES
builtins.object
plotnine.geoms.annotate.annotate
plotnine.geoms.annotation_logticks.annotation_logticks
plotnine.geoms.annotation_stripes.annotation_stripes
plotnine.geoms.geom_path.arrow
plotnine.geoms.geom.geom(builtins.object)
plotnine.geoms.geom_abline.geom_abline
plotnine.geoms.geom_blank.geom_blank
plotnine.geoms.geom_boxplot.geom_boxplot
plotnine.geoms.geom_crossbar.geom_crossbar
plotnine.geoms.geom_dotplot.geom_dotplot
plotnine.geoms.geom_errorbar.geom_errorbar
plotnine.geoms.geom_errorbarh.geom_errorbarh
plotnine.geoms.geom_hline.geom_hline
plotnine.geoms.geom_linerange.geom_linerange
plotnine.geoms.geom_map.geom_map
plotnine.geoms.geom_path.geom_path
plotnine.geoms.geom_density_2d.geom_density_2d
plotnine.geoms.geom_freqpoly.geom_freqpoly
plotnine.geoms.geom_line.geom_line
plotnine.geoms.geom_qq_line.geom_qq_line
plotnine.geoms.geom_quantile.geom_quantile
plotnine.geoms.geom_step.geom_step
plotnine.geoms.geom_point.geom_point
plotnine.geoms.geom_count.geom_count
plotnine.geoms.geom_jitter.geom_jitter
plotnine.geoms.geom_pointdensity.geom_pointdensity
plotnine.geoms.geom_qq.geom_qq
plotnine.geoms.geom_sina.geom_sina
plotnine.geoms.geom_pointrange.geom_pointrange
plotnine.geoms.geom_polygon.geom_polygon
plotnine.geoms.geom_raster.geom_raster
plotnine.geoms.geom_rect.geom_rect
plotnine.geoms.geom_bar.geom_bar
plotnine.geoms.geom_col.geom_col
plotnine.geoms.geom_histogram.geom_histogram
plotnine.geoms.geom_bin_2d.geom_bin_2d
plotnine.geoms.geom_tile.geom_tile
plotnine.geoms.geom_ribbon.geom_ribbon
plotnine.geoms.geom_area.geom_area
plotnine.geoms.geom_density.geom_density
plotnine.geoms.geom_rug.geom_rug
plotnine.geoms.geom_segment.geom_segment
plotnine.geoms.geom_spoke.geom_spoke
plotnine.geoms.geom_smooth.geom_smooth
plotnine.geoms.geom_text.geom_text
plotnine.geoms.geom_label.geom_label
plotnine.geoms.geom_violin.geom_violin
plotnine.geoms.geom_vline.geom_vline
class annotate(builtins.object)
| annotate(geom: 'str | type[geom_base_class]', x: 'float | None' = None, y: 'float | None' = None, xmin: 'float | None' = None, xmax: 'float | None' = None, xend: 'float | None' = None, xintercept: 'float | None' = None, ymin: 'float | None' = None, ymax: 'float | None' = None, yend: 'float | None' = None, yintercept: 'float | None' = None, **kwargs: 'Any')
|
| Create an annotation layer
|
| Parameters
| ----------
| geom : geom or str
| geom to use for annotation, or name of geom (e.g. 'point').
| x : float
| Position
| y : float
| Position
| xmin : float
| Position
| ymin : float
| Position
| xmax : float
| Position
| ymax : float
| Position
| xend : float
| Position
| yend : float
| Position
| xintercept : float
| Position
| yintercept : float
| Position
| kwargs : dict
| Other aesthetics or parameters to the geom.
|
| Notes
| -----
| The positioning aethetics ``x, y, xmin, ymin, xmax, ymax, xend, yend,
| xintercept, yintercept`` depend on which `geom` is used.
|
| You should choose or ignore accordingly.
|
| All `geoms` are created with :code:`stat='identity'`.
|
| Methods defined here:
|
| __init__(self, geom: 'str | type[geom_base_class]', x: 'float | None' = None, y: 'float | None' = None, xmin: 'float | None' = None, xmax: 'float | None' = None, xend: 'float | None' = None, xintercept: 'float | None' = None, ymin: 'float | None' = None, ymax: 'float | None' = None, yend: 'float | None' = None, yintercept: 'float | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add to ggplot
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this annotation
|
| Returns
| -------
| out : layer
| Layer
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| __annotations__ = {'_annotation_geom': 'geom_base_class'}
class annotation_logticks(plotnine.geoms.annotate.annotate)
| annotation_logticks(sides: 'str' = 'bl', alpha: 'float' = 1, color: 'str | tuple[float, ...]' = 'black', size: 'float' = 0.5, linetype: 'str | tuple[float, ...]' = 'solid', lengths: 'TupleFloat3' = (0.036, 0.0225, 0.012), base: 'float | None' = None)
|
| Marginal log ticks.
|
| If added to a plot that does not have a log10 axis
| on the respective side, a warning will be issued.
|
| Parameters
| ----------
| sides : str (default: bl)
| Sides onto which to draw the marks. Any combination
| chosen from the characters ``btlr``, for *bottom*, *top*,
| *left* or *right* side marks. If ``coord_flip()`` is used,
| these are the sides *after* the flip.
| alpha : float (default: 1)
| Transparency of the ticks
| color : str | tuple (default: 'black')
| Colour of the ticks
| size : float
| Thickness of the ticks
| linetype : 'solid' | 'dashed' | 'dashdot' | 'dotted' | tuple
| Type of line. Default is *solid*.
| lengths: tuple (default (0.036, 0.0225, 0.012))
| length of the ticks drawn for full / half / tenth
| ticks relative to panel size
| base : float (default: None)
| Base of the logarithm in which the ticks will be
| calculated. If ``None``, the base used to log transform
| the scale will be used.
|
| Method resolution order:
| annotation_logticks
| plotnine.geoms.annotate.annotate
| builtins.object
|
| Methods defined here:
|
| __init__(self, sides: 'str' = 'bl', alpha: 'float' = 1, color: 'str | tuple[float, ...]' = 'black', size: 'float' = 0.5, linetype: 'str | tuple[float, ...]' = 'solid', lengths: 'TupleFloat3' = (0.036, 0.0225, 0.012), base: 'float | None' = None)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.annotate.annotate:
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add to ggplot
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this annotation
|
| Returns
| -------
| out : layer
| Layer
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.annotate.annotate:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.annotate.annotate:
|
| __annotations__ = {'_annotation_geom': 'geom_base_class'}
class annotation_stripes(plotnine.geoms.annotate.annotate)
| annotation_stripes(fill: 'Sequence[str]' = ('#AAAAAA', '#CCCCCC'), fill_range: "Literal['auto', 'cycle', 'no', 'nocycle']" = 'auto', direction: "Literal['horizontal', 'vertical']" = 'vertical', extend: 'TupleFloat2' = (0, 1), **kwargs: 'Any')
|
| Alternating stripes, centered around each label.
|
| Useful as a background for geom_jitter.
|
| Parameters
| ----------
| fill : list-like
| List of colors for the strips. The default is
| `("#AAAAAA", "#CCCCCC")`
| fill_range: 'cycle' | 'nocycle' | 'auto' | 'no'
| How to fill stripes beyond the range of scale::
|
| 'cycle' # keep cycling the colors of the
| # stripes after the range ends
| 'nocycle' # stop cycling the colors of the
| # stripes after the range ends
| 'auto' # 'cycle' for continuous scales and
| # 'nocycle' for discrete scales.
| 'no' # Do not add stripes passed the range
| # passed the range of the scales
|
| Default is 'auto'.
| direction : 'vertical' or 'horizontal'
| Orientation of the stripes
| extend : tuple
| Range of the stripes. The default is (0, 1), top to bottom.
| The values should be in the range [0, 1].
| **kwargs : dict
| Other aesthetic parameters for the rectangular stripes.
| They include; *alpha*, *color*, *linetype*, and *size*.
|
| Method resolution order:
| annotation_stripes
| plotnine.geoms.annotate.annotate
| builtins.object
|
| Methods defined here:
|
| __init__(self, fill: 'Sequence[str]' = ('#AAAAAA', '#CCCCCC'), fill_range: "Literal['auto', 'cycle', 'no', 'nocycle']" = 'auto', direction: "Literal['horizontal', 'vertical']" = 'vertical', extend: 'TupleFloat2' = (0, 1), **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.annotate.annotate:
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add to ggplot
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this annotation
|
| Returns
| -------
| out : layer
| Layer
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.annotate.annotate:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.annotate.annotate:
|
| __annotations__ = {'_annotation_geom': 'geom_base_class'}
class arrow(builtins.object)
| arrow(angle: 'float' = 30, length: 'float' = 0.2, ends: "Literal['first', 'last', 'both']" = 'last', type: "Literal['open', 'closed']" = 'open')
|
| Define arrow (actually an arrowhead)
|
| This is used to define arrow heads for
| :class:`.geom_path`.
|
| Parameters
| ----------
| angle : int | float
| angle in degrees between the tail a
| single edge.
| length : int | float
| of the edge in "inches"
| ends : str in ``['last', 'first', 'both']``
| At which end of the line to draw the
| arrowhead
| type : str in ``['open', 'closed']``
| When it is closed, it is also filled
|
| Methods defined here:
|
| __init__(self, angle: 'float' = 30, length: 'float' = 0.2, ends: "Literal['first', 'last', 'both']" = 'last', type: "Literal['open', 'closed']" = 'open')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', constant: 'bool' = True, **params: 'Any')
| Draw arrows at the end(s) of the lines
|
| 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.
| constant: bool
| If the path attributes vary along the way. If false,
| the arrows are per segment of the path
| params : dict
| Combined parameters for the geom and stat. Also
| includes the 'zorder'.
|
| get_paths(self, x1: 'npt.ArrayLike', y1: 'npt.ArrayLike', x2: 'npt.ArrayLike', y2: 'npt.ArrayLike', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes') -> 'list[Path]'
| Compute paths that create the arrow heads
|
| Parameters
| ----------
| x1, y1, x2, y2 : array_like
| List of points that define the tails of the arrows.
| The arrow heads will be at x1, y1. If you need them
| at x2, y2 reverse the input.
|
| 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.
|
| Returns
| -------
| out : list of Path
| Paths that create arrow heads
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
class geom_abline(plotnine.geoms.geom.geom)
| geom_abline(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Lines specified by slope and intercept
|
|
| .. rubric:: Usage
|
| ::
|
| geom_abline(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=False, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **intercept**
| **slope**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: False)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_abline
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'inherit_aes': False, 'na_rm': False, 'position': 'i...
|
| REQUIRED_AES = {'intercept', 'slope'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_area(plotnine.geoms.geom_ribbon.geom_ribbon)
| geom_area(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Area plot
|
| An area plot is a special case of geom_ribbon,
| where the minimum of the range is fixed to 0,
| and the position adjustment defaults to 'stack'.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_area(mapping=None, data=None, stat='identity', position='stack',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| outline_type='upper', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'none'`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| where :py:`True`
| =============== ===============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| where
| Define where to exclude horizontal regions from being filled.
| Regions between any two ``False`` values are skipped.
| For sensible demarcation the value used in the *where* predicate
| expression should match the ``ymin`` value or expression. i.e.
|
| ::
|
| aes(ymin=0, ymax='col1', where='col1 > 0') # good
| aes(ymin=0, ymax='col1', where='col1 > 10') # bad
|
| aes(ymin=col2, ymax='col1', where='col1 > col2') # good
| aes(ymin=col2, ymax='col1', where='col1 > col3') # bad
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_ribbon
|
| Method resolution order:
| geom_area
| plotnine.geoms.geom_ribbon.geom_ribbon
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'outline_type': 'upper', 'position':...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_ribbon.geom_ribbon:
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_ribbon.geom_ribbon:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_ribbon.geom_ribbon:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'none', 'fill': '#333333', 'linety...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_ribbon.geom_ribbon'>
| Ribbon plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_ribbon(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| outline_type='both', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'none'`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| where :py:`True`
| =============== ===============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| where
| Define where to exclude horizontal regions from being filled.
| Regions between any two ``False`` values are skipped.
| For sensible demarcation the value used in the *where* predicate
| expression should match the ``ymin`` value or expression. i.e.
|
| ::
|
| aes(ymin=0, ymax='col1', where='col1 > 0') # good
| aes(ymin=0, ymax='col1', where='col1 > 10') # bad
|
| aes(ymin=col2, ymax='col1', where='col1 > col2') # good
| aes(ymin=col2, ymax='col1', where='col1 > col3') # bad
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| outline_type : 'upper' | 'lower' | 'both' | 'full'
| How to stroke to outline of the region / area.
| * 'upper' - draw only upper bounding line'
| * 'lower' - draw only lower bounding line'
| * 'both' - draw both upper & lower bounding lines
| * 'full' - draw closed polygon around the area.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_bar(plotnine.geoms.geom_rect.geom_rect)
| geom_bar(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Bar plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_bar(mapping=None, data=None, stat='count', position='stack', na_rm=False,
| inherit_aes=True, show_legend=None, raster=False, width=None,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_count)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, optional (default None)
| Bar width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
|
| See Also
| --------
| plotnine.geoms.geom_histogram
|
| Method resolution order:
| geom_bar
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'stack', 'stat': 'count'...
|
| NON_MISSING_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_rect.geom_rect:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_rect.geom_rect'>
| Rectangles
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rect(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
geom_bin2d = class geom_bin_2d(plotnine.geoms.geom_rect.geom_rect)
| geom_bin2d(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Heatmap of 2d bin counts
|
| Divides the plane into rectangles, counts the number of
| cases in each rectangle, and then (by default) maps the number
| of cases to the rectangle's fill. This is a useful alternative
| to geom_point in the presence of overplotting.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_bin_2d(mapping=None, data=None, stat='bin_2d', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_bin_2d)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_bin_2d
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'bin...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_rect.geom_rect:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| REQUIRED_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_rect.geom_rect'>
| Rectangles
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rect(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_bin_2d(plotnine.geoms.geom_rect.geom_rect)
| geom_bin_2d(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Heatmap of 2d bin counts
|
| Divides the plane into rectangles, counts the number of
| cases in each rectangle, and then (by default) maps the number
| of cases to the rectangle's fill. This is a useful alternative
| to geom_point in the presence of overplotting.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_bin_2d(mapping=None, data=None, stat='bin_2d', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_bin_2d)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_bin_2d
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'bin...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_rect.geom_rect:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| REQUIRED_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_rect.geom_rect'>
| Rectangles
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rect(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_blank(plotnine.geoms.geom.geom)
| geom_blank(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| An empty plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_blank(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_blank
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| DEFAULT_AES = {}
|
| NON_MISSING_AES = set()
|
| REQUIRED_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_boxplot(plotnine.geoms.geom.geom)
| geom_boxplot(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Box and whiskers plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_boxplot(mapping=None, data=None, stat='boxplot', position='dodge2',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| width=None, outlier_size=1.5, notch=False, outlier_color=None,
| fatten=2, outlier_shape='o', outlier_alpha=1, notchwidth=0.5,
| varwidth=False, outlier_stroke=0.5, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **lower**
| **middle**
| **upper**
| **x**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'#333333'`
| fill :py:`'white'`
| group
| linetype :py:`'solid'`
| shape :py:`'o'`
| size :py:`0.5`
| weight :py:`1`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_boxplot)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_dodge2)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, optional (default None)
| Box width. If :py:`None`, the width is set to
| `90%` of the resolution of the data. Note that if the stat
| has a width parameter, that takes precedence over this one.
| outlier_alpha : float, optional (default: 1)
| Transparency of the outlier points.
| outlier_color : str or tuple, optional (default: None)
| Color of the outlier points.
| outlier_shape : str, optional (default: o)
| Shape of the outlier points. An empty string hides the outliers.
| outlier_size : float, optional (default: 1.5)
| Size of the outlier points.
| outlier_stroke : float, optional (default: 0.5)
| Stroke-size of the outlier points.
| notch : bool, optional (default: False)
| Whether the boxes should have a notch.
| varwidth : bool, optional (default: False)
| If :py:`True`, boxes are drawn with widths proportional to
| the square-roots of the number of observations in the
| groups.
| notchwidth : float, optional (default: 0.5)
| Width of notch relative to the body width.
| fatten : float, optional (default: 2)
| A multiplicative factor used to increase the size of the
| middle bar across the box.
|
| Method resolution order:
| geom_boxplot
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': '#333333', 'fill': 'white', 'linet...
|
| DEFAULT_PARAMS = {'fatten': 2, 'na_rm': False, 'notch': False, 'notchw...
|
| REQUIRED_AES = {'lower', 'middle', 'upper', 'x', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_col(plotnine.geoms.geom_bar.geom_bar)
| geom_col(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Bar plot with base on the x-axis
|
| This is an alternate version of :class:`geom_bar` that maps
| the height of bars to an existing variable in your data. If
| you want the height of the bar to represent a count of cases,
| use :class:`geom_bar`.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_col(mapping=None, data=None, stat='identity', position='stack',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| width=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, (default: None)
| Bar width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
|
| See Also
| --------
| plotnine.geoms.geom_bar
|
| Method resolution order:
| geom_col
| plotnine.geoms.geom_bar.geom_bar
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'stack', 'stat': 'identi...
|
| NON_MISSING_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_bar.geom_bar:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_rect.geom_rect:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_bar.geom_bar'>
| Bar plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_bar(mapping=None, data=None, stat='count', position='stack', na_rm=False,
| inherit_aes=True, show_legend=None, raster=False, width=None,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_count)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, optional (default None)
| Bar width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
|
| See Also
| --------
| plotnine.geoms.geom_histogram
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_count(plotnine.geoms.geom_point.geom_point)
| geom_count(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Plot overlapping points
|
| This is a variant :class:`geom_point` that counts the number
| of observations at each location, then maps the count to point
| area. It useful when you have discrete data and overplotting.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_count(mapping=None, data=None, stat='sum', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_sum)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_count
| plotnine.geoms.geom_point.geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'sum...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_point.geom_point:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_point.geom_point'>
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_crossbar(plotnine.geoms.geom.geom)
| geom_crossbar(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Vertical interval represented by a crossbar
|
|
| .. rubric:: Usage
|
| ::
|
| geom_crossbar(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| width=0.5, fatten=2, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float or None, optional (default: 0.5)
| Box width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
| fatten : float, optional (default: 2)
| A multiplicative factor used to increase the size of the
| middle bar across the box.
|
| Method resolution order:
| geom_crossbar
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle with a horizontal strike in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'linetype':...
|
| DEFAULT_PARAMS = {'fatten': 2, 'na_rm': False, 'position': 'identity',...
|
| REQUIRED_AES = {'x', 'y', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_density(plotnine.geoms.geom_area.geom_area)
| geom_density(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Smooth density estimate
|
|
| .. rubric:: Usage
|
| ::
|
| geom_density(mapping=None, data=None, stat='density', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| outline_type='upper', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| weight :py:`1`
| where :py:`True`
| ============= =============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| where
| Define where to exclude horizontal regions from being filled.
| Regions between any two ``False`` values are skipped.
| For sensible demarcation the value used in the *where* predicate
| expression should match the ``ymin`` value or expression. i.e.
|
| ::
|
| aes(ymin=0, ymax='col1', where='col1 > 0') # good
| aes(ymin=0, ymax='col1', where='col1 > 10') # bad
|
| aes(ymin=col2, ymax='col1', where='col1 > col2') # good
| aes(ymin=col2, ymax='col1', where='col1 > col3') # bad
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_density)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_ribbon
|
| Method resolution order:
| geom_density
| plotnine.geoms.geom_area.geom_area
| plotnine.geoms.geom_ribbon.geom_ribbon
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'linetype':...
|
| DEFAULT_PARAMS = {'na_rm': False, 'outline_type': 'upper', 'position':...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_area.geom_area:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_area.geom_area:
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_ribbon.geom_ribbon:
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_ribbon.geom_ribbon:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_area.geom_area'>
| Area plot
|
| An area plot is a special case of geom_ribbon,
| where the minimum of the range is fixed to 0,
| and the position adjustment defaults to 'stack'.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_area(mapping=None, data=None, stat='identity', position='stack',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| outline_type='upper', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'none'`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| where :py:`True`
| =============== ===============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| where
| Define where to exclude horizontal regions from being filled.
| Regions between any two ``False`` values are skipped.
| For sensible demarcation the value used in the *where* predicate
| expression should match the ``ymin`` value or expression. i.e.
|
| ::
|
| aes(ymin=0, ymax='col1', where='col1 > 0') # good
| aes(ymin=0, ymax='col1', where='col1 > 10') # bad
|
| aes(ymin=col2, ymax='col1', where='col1 > col2') # good
| aes(ymin=col2, ymax='col1', where='col1 > col3') # bad
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_ribbon
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_density_2d(plotnine.geoms.geom_path.geom_path)
| geom_density_2d(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| 2D density estimate
|
| This is a 2d version of :class:`~plotnine.geoms.geom_density`.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_density_2d(mapping=None, data=None, stat='density_2d',
| position='identity', na_rm=False, inherit_aes=True,
| show_legend=None, raster=False, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_density_2d)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_density_2d
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'den...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_dotplot(plotnine.geoms.geom.geom)
| geom_dotplot(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Dot plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_dotplot(mapping=None, data=None, stat='bindot', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| stackdir='up', stackratio=1, dotsize=1, stackgroups=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`'black'`
| group
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_bindot)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| stackdir : str (default: up)
| Direction in which to stack the dots. Options are
| :py:`['up', 'down', 'center', 'centerwhole']`
| stackratio : float (default: 1)
| How close to stack the dots. If value is less than 1,
| the dots overlap, if greater than 1 they are spaced.
| dotsize : float (default: 1)
| Diameter of dots relative to ``binwidth``.
| stackgroups : bool (default: False)
| If :py:`True`, the dots are stacked across groups.
|
| See Also
| --------
| plotnine.stats.stat_bindot
|
| Method resolution order:
| geom_dotplot
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': 'black'}
|
| DEFAULT_PARAMS = {'dotsize': 1, 'na_rm': False, 'position': 'identity'...
|
| NON_MISSING_AES = {'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_errorbar(plotnine.geoms.geom.geom)
| geom_errorbar(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Vertical interval represented as an errorbar
|
|
| .. rubric:: Usage
|
| ::
|
| geom_errorbar(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| width=0.5, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float or None, optional (default: 0.5)
| Bar width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
|
| Method resolution order:
| geom_errorbar
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'x', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_errorbarh(plotnine.geoms.geom.geom)
| geom_errorbarh(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Horizontal interval represented as an errorbar
|
|
| .. rubric:: Usage
|
| ::
|
| geom_errorbarh(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| height=0.5, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **xmax**
| **xmin**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| height : float or None, optional (default: 0.5)
| Bar height. If :py:`None`, the height is set to
| `90%` of the resolution of the data.
|
| Method resolution order:
| geom_errorbarh
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'height': 0.5, 'na_rm': False, 'position': 'identity...
|
| REQUIRED_AES = {'xmax', 'xmin', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_freqpoly(plotnine.geoms.geom_path.geom_path)
| geom_freqpoly(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Frequency polygon
|
|
| .. rubric:: Usage
|
| ::
|
| geom_freqpoly(mapping=None, data=None, stat='bin', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| See :class:`~plotnine.geoms.geom_path` for documentation
| of the parameters.
|
| Method resolution order:
| geom_freqpoly
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'arrow': None, 'lineend': 'butt', 'linejoin': 'round...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_histogram(plotnine.geoms.geom_bar.geom_bar)
| geom_histogram(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Histogram
|
|
| .. rubric:: Usage
|
| ::
|
| geom_histogram(mapping=None, data=None, stat='bin', position='stack',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_bin)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_bar
|
| Method resolution order:
| geom_histogram
| plotnine.geoms.geom_bar.geom_bar
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'stack', 'stat': 'bin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_bar.geom_bar:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_bar.geom_bar:
|
| NON_MISSING_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_rect.geom_rect:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_bar.geom_bar'>
| Bar plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_bar(mapping=None, data=None, stat='count', position='stack', na_rm=False,
| inherit_aes=True, show_legend=None, raster=False, width=None,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_count)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_stack)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, optional (default None)
| Bar width. If :py:`None`, the width is set to
| `90%` of the resolution of the data.
|
| See Also
| --------
| plotnine.geoms.geom_histogram
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_hline(plotnine.geoms.geom.geom)
| geom_hline(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Horizontal line
|
|
| .. rubric:: Usage
|
| ::
|
| geom_hline(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=False, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============== ==============
| Aesthetic Default value
| ============== ==============
| **yintercept**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============== ==============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: False)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_hline
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'inherit_aes': False, 'na_rm': False, 'position': 'i...
|
| REQUIRED_AES = {'yintercept'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_jitter(plotnine.geoms.geom_point.geom_point)
| geom_jitter(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Scatter plot with points jittered to reduce overplotting
|
|
| .. rubric:: Usage
|
| ::
|
| geom_jitter(mapping=None, data=None, stat='identity', position='jitter',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| random_state=None, width=None, height=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_jitter)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| width : float, optional
| Proportion to jitter in horizontal direction.
| The default value is that from
| :class:`~plotnine.positions.position_jitter`
| height : float, optional
| Proportion to jitter in vertical direction.
| The default value is that from
| :class:`~plotnine.positions.position_jitter`.
| random_state : int or ~numpy.random.RandomState, optional
| Seed or Random number generator to use. If ``None``, then
| numpy global generator :class:`numpy.random` is used.
|
| See Also
| --------
| plotnine.positions.position_jitter
| plotnine.geoms.geom_point
|
| Method resolution order:
| geom_jitter
| plotnine.geoms.geom_point.geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'height': None, 'na_rm': False, 'position': 'jitter'...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_point.geom_point:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_point.geom_point'>
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_label(plotnine.geoms.geom_text.geom_text)
| geom_label(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Textual annotations with a background
|
|
| .. rubric:: Usage
|
| ::
|
| geom_label(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| path_effects=None, label_size=0.7, boxstyle='round', family=None,
| parse=False, nudge_y=0, fontstyle='normal', fontweight='normal',
| label_padding=0.25, label_r=0.25, format_string=None, nudge_x=0,
| boxcolor=None, adjust_text=None, tooth_size=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============== ==============
| Aesthetic Default value
| ============== ==============
| **label**
| **x**
| **y**
| alpha :py:`1`
| angle :py:`0`
| color :py:`'black'`
| fill :py:`'white'`
| group
| ha :py:`'center'`
| lineheight :py:`1.2`
| size :py:`11`
| va :py:`'center'`
| ============== ==============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| ha
| Horizontal alignment. One of *left*, *center* or *right.*
|
| va
| Vertical alignment. One of *top*, *center*, *bottom*, *baseline*.
|
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| boxstyle : str, optional (default: round)
| Options are::
|
| 'circle'
| 'darrow'
| 'larrow'
| 'rarrow'
| 'round '
| 'round4'
| 'roundtooth'
| 'sawtooth'
| 'square'
| boxcolor: None, str or rgba tuple (default: None)
| Color of box around the text. If None, the color is
| the same as the text.
| label_padding : float, optional (default: 0.25)
| Amount of padding
| label_r : float, optional (default: 0.25)
| Rounding radius of corners.
| label_size : float, optional (default: 0.7)
| Linewidth of the label boundary.
| tooth_size : float, optional (default: None)
| Size of the ``roundtooth`` or ``sawtooth`` if they
| are the chosen *boxstyle*. The default depends
| on Matplotlib
|
| See Also
| --------
| plotnine.geoms.geom_text : For documentation of the
| parameters. :class:`matplotlib.patches.BoxStyle` for the
| parameters that affect the boxstyle.
|
| Method resolution order:
| geom_label
| plotnine.geoms.geom_text.geom_text
| plotnine.geoms.geom.geom
| builtins.object
|
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw letter 'a' in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'angle': 0, 'color': 'black', 'fill': 'whit...
|
| DEFAULT_PARAMS = {'adjust_text': None, 'boxcolor': None, 'boxstyle': '...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_text.geom_text:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_text.geom_text:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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 and other attributes inherited from plotnine.geoms.geom_text.geom_text:
|
| REQUIRED_AES = {'label', 'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_text.geom_text'>
| Textual annotations
|
|
| .. rubric:: Usage
|
| ::
|
| geom_text(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| path_effects=None, family=None, parse=False, fontstyle='normal',
| nudge_y=0, fontweight='normal', format_string=None, nudge_x=0,
| adjust_text=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============== ==============
| Aesthetic Default value
| ============== ==============
| **label**
| **x**
| **y**
| alpha :py:`1`
| angle :py:`0`
| color :py:`'black'`
| group
| ha :py:`'center'`
| lineheight :py:`1.2`
| size :py:`11`
| va :py:`'center'`
| ============== ==============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| ha
| Horizontal alignment. One of *left*, *center* or *right.*
|
| va
| Vertical alignment. One of *top*, *center*, *bottom*, *baseline*.
|
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| parse : bool (default: False)
| If :py:`True`, the labels will be rendered with
| `latex <http://matplotlib.org/users/usetex.html>`_.
| family : str (default: None)
| Font family.
| fontweight : int or str (default: normal)
| Font weight.
| fontstyle : str (default: normal)
| Font style. One of *normal*, *italic* or *oblique*
| nudge_x : float (default: 0)
| Horizontal adjustment to apply to the text
| nudge_y : float (default: 0)
| Vertical adjustment to apply to the text
| adjust_text: dict (default: None)
| Parameters to :class:`adjustText.adjust_text` will repel
| overlapping texts. This parameter takes priority of over
| ``nudge_x`` and ``nudge_y``.
|
| ``adjust_text`` does not work well when it is used in the
| first layer of the plot, or if it is the only layer.
| For more see the documentation at
| https://github.com/Phlya/adjustText/wiki .
| format_string : str (default: None)
| If not :py:`None`, then the text is formatted with this
| string using :meth:`str.format` e.g::
|
| # 2.348 -> "2.35%"
| geom_text(format_string="{:.2f}%")
|
| path_effects : list (default: None)
| If not :py:`None`, then the text will use these effects.
| See `path_effects
| <https://matplotlib.org/tutorials/advanced/patheffects_guide.html>`_
| documentation for more details.
|
| See Also
| --------
| plotnine.geoms.geom_label
| matplotlib.text.Text
| matplotlib.patheffects
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_line(plotnine.geoms.geom_path.geom_path)
| geom_line(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_line(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_path : For documentation of other parameters.
|
| Method resolution order:
| geom_line
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'arrow': None, 'lineend': 'butt', 'linejoin': 'round...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_linerange(plotnine.geoms.geom.geom)
| geom_linerange(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Vertical interval represented by lines
|
|
| .. rubric:: Usage
|
| ::
|
| geom_linerange(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_linerange
| plotnine.geoms.geom.geom
| builtins.object
|
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'x', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_map(plotnine.geoms.geom.geom)
| geom_map(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Draw map feature
|
| The map feature are drawn without any special projections.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_map(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **geometry**
| alpha :py:`1`
| color :py:`'#111111'`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| shape :py:`'o'`
| size :py:`0.5`
| stroke :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| Notes
| -----
| This geom is best suited for plotting a shapefile read into
| geopandas dataframe. The dataframe should have a ``geometry``
| column.
|
| Method resolution order:
| geom_map
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': '#111111', 'fill': '#333333', 'lin...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'geometry'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_path(plotnine.geoms.geom.geom)
| geom_path(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
| Method resolution order:
| geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'arrow': None, 'lineend': 'butt', 'linejoin': 'round...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_point(plotnine.geoms.geom.geom)
| geom_point(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_pointdensity(plotnine.geoms.geom_point.geom_point)
| geom_pointdensity(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Scatterplot with density estimation at each point
|
|
| .. rubric:: Usage
|
| ::
|
| geom_pointdensity(mapping=None, data=None, stat='pointdensity',
| position='identity', na_rm=False, inherit_aes=True,
| show_legend=None, raster=False, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_pointdensity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_pointdensity
| plotnine.geoms.geom_point.geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'poi...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_point.geom_point:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_point.geom_point'>
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_pointrange(plotnine.geoms.geom.geom)
| geom_pointrange(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Vertical interval represented by a line with a point
|
|
| .. rubric:: Usage
|
| ::
|
| geom_pointrange(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| fatten=4, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| linetype :py:`'solid'`
| shape :py:`'o'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| fatten : float, optional (default: 2)
| A multiplicative factor used to increase the size of the
| point along the line-range.
|
| Method resolution order:
| geom_pointrange
| plotnine.geoms.geom.geom
| builtins.object
|
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'linetype':...
|
| DEFAULT_PARAMS = {'fatten': 4, 'na_rm': False, 'position': 'identity',...
|
| REQUIRED_AES = {'x', 'y', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_polygon(plotnine.geoms.geom.geom)
| geom_polygon(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Polygon, a filled path
|
|
| .. rubric:: Usage
|
| ::
|
| geom_polygon(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| Notes
| -----
| All paths in the same ``group`` aesthetic value make up a polygon.
|
| Method resolution order:
| geom_polygon
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#333333', 'linetype...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_qq(plotnine.geoms.geom_point.geom_point)
| geom_qq(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Quantile-Quantile plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_qq(mapping=None, data=None, stat='qq', position='identity', na_rm=False,
| inherit_aes=True, show_legend=None, raster=False, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_qq)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_qq
| plotnine.geoms.geom_point.geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'qq'...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_point.geom_point:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_point.geom_point'>
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_qq_line(plotnine.geoms.geom_path.geom_path)
| geom_qq_line(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Quantile-Quantile Line plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_qq_line(mapping=None, data=None, stat='qq_line', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_qq_line)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_qq_line
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'qq_...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_quantile(plotnine.geoms.geom_path.geom_path)
| geom_quantile(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Quantile lines from a quantile regression
|
|
| .. rubric:: Usage
|
| ::
|
| geom_quantile(mapping=None, data=None, stat='quantile', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| lineend='butt', linejoin='round', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'#3366FF'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_quantile)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
|
| Method resolution order:
| geom_quantile
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': '#3366FF', 'linetype': 'solid', 's...
|
| DEFAULT_PARAMS = {'lineend': 'butt', 'linejoin': 'round', 'na_rm': Fal...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_raster(plotnine.geoms.geom.geom)
| geom_raster(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Rasterized Rectangles specified using center points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_raster(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=True,
| interpolation=None, filterrad=4.0, vjust=0.5, hjust=0.5, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| fill :py:`'#333333'`
| group
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: True)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| hjust : float (default: 0.5)
| Horizontal justification for the rectangle at point ``x``.
| Default is 0.5, which centers the rectangle horizontally.
| Must be in the range ``[0, 1]``.
| vjust : float (default: 0.5)
| Vertical justification for the rectangle at point ``y``
| Default is 0.5, which centers the rectangle vertically.
| Must be in the range ``[0, 1]``.
| interpolation : str | None (default: None)
| How to calculate values between the center points of
| adjacent rectangles. The default is :py:`None` not to
| interpolate. Allowed values are:
| :py:`'none', 'antialiased', 'nearest', 'bilinear', 'bicubic',`
| :py:`'spline16', 'spline36', 'hanning', 'hamming', 'hermite',`
| :py:`'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel',`
| :py:`'mitchell', 'sinc', 'lanczos', 'blackman'`
|
| filterrad : float, (default: 4.0)
| The filter radius for filters that have a radius parameter, i.e.
| when interpolation is one of: *'sinc', 'lanczos' or 'blackman'*.
| Must be a number greater than zero.
|
| See Also
| --------
| plotnine.geoms.geom_rect
| plotnine.geoms.geom_tile
|
| Method resolution order:
| geom_raster
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'fill': '#333333'}
|
| DEFAULT_PARAMS = {'filterrad': 4.0, 'hjust': 0.5, 'interpolation': Non...
|
| NON_MISSING_AES = {'fill', 'xmax', 'xmin', 'ymax', 'ymin'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_rect(plotnine.geoms.geom.geom)
| geom_rect(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Rectangles
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rect(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#595959', 'linetype...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'xmax', 'xmin', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_ribbon(plotnine.geoms.geom.geom)
| geom_ribbon(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Ribbon plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_ribbon(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| outline_type='both', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`'none'`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| where :py:`True`
| =============== ===============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| where
| Define where to exclude horizontal regions from being filled.
| Regions between any two ``False`` values are skipped.
| For sensible demarcation the value used in the *where* predicate
| expression should match the ``ymin`` value or expression. i.e.
|
| ::
|
| aes(ymin=0, ymax='col1', where='col1 > 0') # good
| aes(ymin=0, ymax='col1', where='col1 > 10') # bad
|
| aes(ymin=col2, ymax='col1', where='col1 > col2') # good
| aes(ymin=col2, ymax='col1', where='col1 > col3') # bad
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| outline_type : 'upper' | 'lower' | 'both' | 'full'
| How to stroke to outline of the region / area.
| * 'upper' - draw only upper bounding line'
| * 'lower' - draw only lower bounding line'
| * 'both' - draw both upper & lower bounding lines
| * 'full' - draw closed polygon around the area.
|
| Method resolution order:
| geom_ribbon
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'none', 'fill': '#333333', 'linety...
|
| DEFAULT_PARAMS = {'na_rm': False, 'outline_type': 'both', 'position': ...
|
| REQUIRED_AES = {'x', 'ymax', 'ymin'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_rug(plotnine.geoms.geom.geom)
| geom_rug(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Marginal rug plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rug(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| sides='bl', length=0.03, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| sides : str (default: bl)
| Sides onto which to draw the marks. Any combination
| chosen from the characters ``btlr``, for *bottom*, *top*,
| *left* or *right* side marks.
| length: float
| length of marks in fractions of
| horizontal/vertical panel size (default 0.03)
|
| Method resolution order:
| geom_rug
| plotnine.geoms.geom.geom
| builtins.object
|
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'length': 0.03, 'na_rm': False, 'position': 'identit...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| REQUIRED_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_segment(plotnine.geoms.geom.geom)
| geom_segment(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Line segments
|
|
| .. rubric:: Usage
|
| ::
|
| geom_segment(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **xend**
| **y**
| **yend**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.geom_path.arrow : for adding arrowhead(s)
| to segments.
|
| Method resolution order:
| geom_segment
| plotnine.geoms.geom.geom
| builtins.object
|
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'arrow': None, 'lineend': 'butt', 'na_rm': False, 'p...
|
| NON_MISSING_AES = {'linetype', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'xend', 'y', 'yend'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_sina(plotnine.geoms.geom_point.geom_point)
| geom_sina(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Draw a sina plot
|
| A sina plot is a data visualization chart suitable for plotting
| any single variable in a multiclass dataset. It is an enhanced
| jitter strip chart, where the width of the jitter is controlled
| by the density distribution of the data within each class.
|
|
| .. rubric:: Usage
|
| ::
|
| geom_sina(mapping=None, data=None, stat='sina', position='dodge', na_rm=False,
| inherit_aes=True, show_legend=None, raster=False, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_sina)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_dodge)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.stats.stat_sina
|
| References
| ----------
| Sidiropoulos, N., S. H. Sohi, T. L. Pedersen, B. T. Porse, O. Winther,
| N. Rapin, and F. O. Bagger. 2018.
| "SinaPlot: An Enhanced Chart for Simple and Truthful Representation of
| Single Observations over Multiple Classes."
| J. Comp. Graph. Stat 27: 673–76.
|
| Method resolution order:
| geom_sina
| plotnine.geoms.geom_point.geom_point
| plotnine.geoms.geom.geom
| builtins.object
|
| Data and other attributes defined here:
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'dodge', 'stat': 'sina'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_point.geom_point:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a point in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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 and other attributes inherited from plotnine.geoms.geom_point.geom_point:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'fill': None, 'shape': 'o...
|
| NON_MISSING_AES = {'color', 'shape', 'size'}
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_point.geom_point'>
| Plot points (Scatter plot)
|
|
| .. rubric:: Usage
|
| ::
|
| geom_point(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| fill :py:`None`
| group
| shape :py:`'o'`
| size :py:`1.5`
| stroke :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_smooth(plotnine.geoms.geom.geom)
| geom_smooth(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| A smoothed conditional mean
|
|
| .. rubric:: Usage
|
| ::
|
| geom_smooth(mapping=None, data=None, stat='smooth', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| legend_fill_ratio=0.5, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`0.4`
| color :py:`'black'`
| fill :py:`'#999999'`
| group
| linetype :py:`'solid'`
| size :py:`1`
| ymax :py:`None`
| ymin :py:`None`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_smooth)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| legend_fill_ratio : float (default: 0.5)
| How much (vertically) of the legend box should be filled by
| the color that indicates the confidence intervals. Should be
| in the range [0, 1].
|
| Method resolution order:
| geom_smooth
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw letter 'a' in the box
|
| Parameters
| ----------
| data : dataframe
| Legend data
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 0.4, 'color': 'black', 'fill': '#999999', 'lin...
|
| DEFAULT_PARAMS = {'legend_fill_ratio': 0.5, 'na_rm': False, 'position'...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_spoke(plotnine.geoms.geom_segment.geom_segment)
| geom_spoke(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Line segment parameterised by location, direction and distance
|
|
| .. rubric:: Usage
|
| ::
|
| geom_spoke(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **angle**
| **radius**
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_segment : For documentation of extra
| parameters.
|
| Method resolution order:
| geom_spoke
| plotnine.geoms.geom_segment.geom_segment
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| REQUIRED_AES = {'angle', 'radius', 'x', 'y'}
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_segment.geom_segment:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_segment.geom_segment:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'arrow': None, 'lineend': 'butt', 'na_rm': False, 'p...
|
| NON_MISSING_AES = {'linetype', 'shape', 'size'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_segment.geom_segment'>
| Line segments
|
|
| .. rubric:: Usage
|
| ::
|
| geom_segment(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **xend**
| **y**
| **yend**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.geom_path.arrow : for adding arrowhead(s)
| to segments.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_step(plotnine.geoms.geom_path.geom_path)
| geom_step(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Stepped connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_step(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| direction='hv', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| direction : str, optional (default: hv)
| One of *hv*, *vh* or *mid*, for horizontal-vertical steps,
| vertical-horizontal steps or steps half-way between adjacent
| x values.
|
| See Also
| --------
| plotnine.geoms.geom_path : For documentation of extra
| parameters.
|
| Method resolution order:
| geom_step
| plotnine.geoms.geom_path.geom_path
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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 and other attributes defined here:
|
| DEFAULT_PARAMS = {'direction': 'hv', 'na_rm': False, 'position': 'iden...
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_path.geom_path:
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_path.geom_path:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a horizontal line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom_path.geom_path:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_path.geom_path'>
| Connected points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_path(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| linejoin='round', lineend='butt', arrow=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============= =============
| Aesthetic Default value
| ============= =============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============= =============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| lineend : str (default: butt)
| Line end style, of of *butt*, *round* or *projecting.*
| This option is applied for solid linetypes.
| linejoin : str (default: round)
| Line join style, one of *round*, *miter* or *bevel*.
| This option is applied for solid linetypes.
| arrow : plotnine.geoms.geom_path.arrow (default: None)
| Arrow specification. Default is no arrow.
|
| See Also
| --------
| plotnine.geoms.arrow : for adding arrowhead(s) to paths.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_text(plotnine.geoms.geom.geom)
| geom_text(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Textual annotations
|
|
| .. rubric:: Usage
|
| ::
|
| geom_text(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| path_effects=None, family=None, parse=False, fontstyle='normal',
| nudge_y=0, fontweight='normal', format_string=None, nudge_x=0,
| adjust_text=None, **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============== ==============
| Aesthetic Default value
| ============== ==============
| **label**
| **x**
| **y**
| alpha :py:`1`
| angle :py:`0`
| color :py:`'black'`
| group
| ha :py:`'center'`
| lineheight :py:`1.2`
| size :py:`11`
| va :py:`'center'`
| ============== ==============
|
| The **bold** aesthetics are required.
|
|
| .. rubric:: Aesthetics Descriptions
|
| ha
| Horizontal alignment. One of *left*, *center* or *right.*
|
| va
| Vertical alignment. One of *top*, *center*, *bottom*, *baseline*.
|
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| parse : bool (default: False)
| If :py:`True`, the labels will be rendered with
| `latex <http://matplotlib.org/users/usetex.html>`_.
| family : str (default: None)
| Font family.
| fontweight : int or str (default: normal)
| Font weight.
| fontstyle : str (default: normal)
| Font style. One of *normal*, *italic* or *oblique*
| nudge_x : float (default: 0)
| Horizontal adjustment to apply to the text
| nudge_y : float (default: 0)
| Vertical adjustment to apply to the text
| adjust_text: dict (default: None)
| Parameters to :class:`adjustText.adjust_text` will repel
| overlapping texts. This parameter takes priority of over
| ``nudge_x`` and ``nudge_y``.
|
| ``adjust_text`` does not work well when it is used in the
| first layer of the plot, or if it is the only layer.
| For more see the documentation at
| https://github.com/Phlya/adjustText/wiki .
| format_string : str (default: None)
| If not :py:`None`, then the text is formatted with this
| string using :meth:`str.format` e.g::
|
| # 2.348 -> "2.35%"
| geom_text(format_string="{:.2f}%")
|
| path_effects : list (default: None)
| If not :py:`None`, then the text will use these effects.
| See `path_effects
| <https://matplotlib.org/tutorials/advanced/patheffects_guide.html>`_
| documentation for more details.
|
| See Also
| --------
| plotnine.geoms.geom_label
| matplotlib.text.Text
| matplotlib.patheffects
|
| Method resolution order:
| geom_text
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw letter 'a' in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'angle': 0, 'color': 'black', 'ha': 'center...
|
| DEFAULT_PARAMS = {'adjust_text': None, 'family': None, 'fontstyle': 'n...
|
| REQUIRED_AES = {'label', 'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_tile(plotnine.geoms.geom_rect.geom_rect)
| geom_tile(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Rectangles specified using a center points
|
|
| .. rubric:: Usage
|
| ::
|
| geom_tile(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#333333'`
| group
| linetype :py:`'solid'`
| size :py:`0.1`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| See Also
| --------
| plotnine.geoms.geom_rect
|
| Method resolution order:
| geom_tile
| plotnine.geoms.geom_rect.geom_rect
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': None, 'fill': '#333333', 'linetype...
|
| DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'ide...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom_rect.geom_rect:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom_rect.geom_rect'>
| Rectangles
|
|
| .. rubric:: Usage
|
| ::
|
| geom_rect(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **xmax**
| **xmin**
| **ymax**
| **ymin**
| alpha :py:`1`
| color :py:`None`
| fill :py:`'#595959'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_violin(plotnine.geoms.geom.geom)
| geom_violin(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Violin Plot
|
|
| .. rubric:: Usage
|
| ::
|
| geom_violin(mapping=None, data=None, stat='ydensity', position='dodge',
| na_rm=False, inherit_aes=True, show_legend=None, raster=False,
| width=None, draw_quantiles=None, style='full', trim=True,
| scale='area', **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| =============== ===============
| Aesthetic Default value
| =============== ===============
| **x**
| **y**
| alpha :py:`1`
| color :py:`'#333333'`
| fill :py:`'white'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| weight :py:`1`
| =============== ===============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_ydensity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_dodge)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: True)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| draw_quantiles : float or [float]
| draw horizontal lines at the given quantiles (0..1)
| of the density estimate.
| style : str, optional (default: 'full')
| The type of violin plot to draw. The options are:
|
| ::
|
| 'full' # Regular (2 sided violins)
| 'left' # Left-sided half violins
| 'right' # Right-sided half violins
| 'left-right' # Alternate (left first) half violins by the group
| 'right-left' # Alternate (right first) half violins by the group
|
| Method resolution order:
| geom_violin
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a rectangle in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': '#333333', 'fill': 'white', 'linet...
|
| DEFAULT_PARAMS = {'draw_quantiles': None, 'na_rm': False, 'position': ...
|
| REQUIRED_AES = {'x', 'y'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
class geom_vline(plotnine.geoms.geom.geom)
| geom_vline(mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
|
| Vertical line
|
|
| .. rubric:: Usage
|
| ::
|
| geom_vline(mapping=None, data=None, stat='identity', position='identity',
| na_rm=False, inherit_aes=False, show_legend=None, raster=False,
| **kwargs)
|
| Only the ``data`` and ``mapping`` can be positional, the rest must
| be keyword arguments. ``**kwargs`` can be aesthetics (or parameters)
| used by the ``stat``.
|
|
| Parameters
| ----------
| mapping : aes, optional
| Aesthetic mappings created with :meth:`~plotnine.aes`. If specified and :py:`inherit.aes=True`, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.
|
| ============== ==============
| Aesthetic Default value
| ============== ==============
| **xintercept**
| alpha :py:`1`
| color :py:`'black'`
| group
| linetype :py:`'solid'`
| size :py:`0.5`
| ============== ==============
|
| The **bold** aesthetics are required.
|
| data : dataframe, optional
| The data to be displayed in this layer. If :py:`None`, the data from from the :py:`ggplot()` call is used. If specified, it overrides the data from the :py:`ggplot()` call.
| stat : str or stat, optional (default: ~plotnine.stats.stat_identity)
| The statistical transformation to use on the data for this layer. If it is a string, it must be the registered and known to Plotnine.
| position : str or position, optional (default: ~plotnine.positions.position_identity)
| Position adjustment. If it is a string, it must be registered and known to Plotnine.
| na_rm : bool, optional (default: False)
| If :py:`False`, removes missing values with a warning. If :py:`True` silently removes missing values.
| inherit_aes : bool, optional (default: False)
| If :py:`False`, overrides the default aesthetics.
| show_legend : bool or dict, optional (default: None)
| Whether this layer should be included in the legends. :py:`None` the default, includes any aesthetics that are mapped. If a :class:`bool`, :py:`False` never includes and :py:`True` always includes. A :class:`dict` can be used to *exclude* specific aesthetis of the layer from showing in the legend. e.g :py:`show_legend={'color': False}`, any other aesthetic are included by default.
| raster : bool, optional (default: False)
| If ``True``, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
|
| Method resolution order:
| geom_vline
| plotnine.geoms.geom.geom
| builtins.object
|
| Methods defined here:
|
| __init__(self, mapping: 'Aes | None' = None, data: 'DataLike | None' = None, **kwargs: 'Any')
| Initialize self. See help(type(self)) for accurate signature.
|
| draw_panel(self, data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| Plot all groups
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| draw_legend(data: 'pd.Series[Any]', da: 'DrawingArea', lyr: 'Layer') -> 'DrawingArea'
| Draw a vertical line in the box
|
| Parameters
| ----------
| data : Series
| Data Row
| da : DrawingArea
| Canvas
| lyr : layer
| Layer
|
| Returns
| -------
| out : DrawingArea
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| DEFAULT_AES = {'alpha': 1, 'color': 'black', 'linetype': 'solid', 'siz...
|
| DEFAULT_PARAMS = {'inherit_aes': False, 'na_rm': False, 'position': 'i...
|
| REQUIRED_AES = {'xintercept'}
|
| ----------------------------------------------------------------------
| Methods inherited from plotnine.geoms.geom.geom:
|
| __deepcopy__(self, memo: 'dict[Any, Any]') -> 'geom'
| Deep copy without copying the self.data dataframe
|
| geoms should not override this method.
|
| __radd__(self, gg: 'Ggplot') -> 'Ggplot'
| Add layer representing geom object on the right
|
| Parameters
| ----------
| gg : ggplot
| ggplot object
|
| Returns
| -------
| out : ggplot
| ggplot object with added layer.
|
| draw_layer(self, data: 'pd.DataFrame', layout: 'Layout', coord: 'Coord', **params: 'Any')
| Draw layer across all panels
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : DataFrame
| DataFrame specific for this layer
| layout : Layout
| Layout object created when the plot is getting
| built
| coord : coord
| Type of coordinate axes
| params : dict
| Combined *geom* and *stat* parameters. Also
| includes the stacking order of the layer in
| the plot (*zorder*)
|
| handle_na(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| Remove rows with NaN values
|
| geoms that infer extra information from missing values
| should override this method. For example
| :class:`~plotnine.geoms.geom_path`.
|
| Parameters
| ----------
| data : dataframe
| Data
|
| Returns
| -------
| out : dataframe
| Data without the NaNs.
|
| 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.
|
| setup_data(self, data: 'pd.DataFrame') -> 'pd.DataFrame'
| 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:
|
| 1. The ``stat`` does not create all the aesthetics (usually
| position aesthetics) required for drawing the ``geom``,
| but those aesthetics can be computed from the available
| data. For example :class:`~plotnine.geoms.geom_boxplot`
| and :class:`~plotnine.geoms.geom_violin`.
|
| 2. The ``geom`` inherits from another ``geom`` (superclass) which
| does the drawing and the superclass requires certain aesthetics
| to be present in the data. For example
| :class:`~plotnine.geoms.geom_tile` and
| :class:`~plotnine.geoms.geom_area`.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| to_layer(self) -> 'Layer'
| Make a layer that represents this geom
|
| Returns
| -------
| out : layer
| Layer
|
| use_defaults(self, data: 'pd.DataFrame', aes_modifiers: 'dict[str, Any]') -> 'pd.DataFrame'
| Combine data with defaults and set aesthetics from parameters
|
| geoms should not override this method.
|
| Parameters
| ----------
| data : dataframe
| Data used for drawing the geom.
| aes_modifiers : dict
| Aesthetics
|
| Returns
| -------
| out : dataframe
| Data used for drawing the geom.
|
| ----------------------------------------------------------------------
| Class methods inherited from plotnine.geoms.geom.geom:
|
| aesthetics() -> 'set[str]' from plotnine.utils.Registry
| Return all the aesthetics for this geom
|
| geoms should not override this method.
|
| ----------------------------------------------------------------------
| Static methods inherited from plotnine.geoms.geom.geom:
|
| draw_group(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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'.
|
| draw_unit(data: 'pd.DataFrame', panel_params: 'panel_view', coord: 'Coord', ax: 'Axes', **params: 'Any')
| 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
| :class:`~plotnine.geoms.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'.
|
| from_stat(stat: 'stat') -> 'geom'
| Return an instantiated geom object
|
| geoms should not override this method.
|
| Parameters
| ----------
| stat : stat
| `stat`
|
| Returns
| -------
| out : geom
| A geom object
|
| Raises
| ------
| PlotnineError
| If unable to create a `geom`.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from plotnine.geoms.geom.geom:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from plotnine.geoms.geom.geom:
|
| NON_MISSING_AES = set()
|
| __annotations__ = {'DEFAULT_AES': 'dict[str, Any]', 'DEFAULT_PARAMS': ...
|
| __base__ = <class 'plotnine.geoms.geom.geom'>
| Base class of all Geoms
|
|
| aes_params = {}
|
| legend_geom = 'point'
DATA
__all__ = ['annotate', 'annotation_logticks', 'annotation_stripes', 'g...
FILE
/Users/sanduniprasadi/Library/r-miniconda-arm64/envs/r-reticulate/lib/python3.9/site-packages/plotnine/geoms/__init__.py
Since we are interested in creating a scatter plot, the geometric representation of the data will be in point form. Therefore we use the geom_point()
function.
To plot the expression of estrogen receptor alpha (ESR1) against that of the transcription factor, GATA3:
# first import the relevant geom function
from plotnine import geom_point
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data
geom_point()
) plot.draw()
Notice that we use the +
sign to add a layer of points to the plot. This concept bears resemblance to Adobe Photoshop, where layers of images can be rearranged and edited independently. In ggplot, each layer is added over the plot in accordance with its position in the code using the +
sign.
Customizing Plots
Adding Colour
The above plot could be made more informative. For instance, the additional information regarding the ER status could be incorporated into the plot. To do this, we can utilize aes()
and specify which column in the metabric
data frame should be represented as the color of the points.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "ER_status"))
geom_point(aes(colour
) plot.draw()
Notice that we specify the colour = ER_status
argument in the aes()
mapping inside the geom_()
function instead of ggplot()
function. Aesthetic mappings can be set in both ggplot()
and individual geom()
layers and we will discuss the difference in the Section: Adding Layers.
To colour points based on a continuous variable, for example: Nottingham prognostic index (NPI):
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "Nottingham_prognostic_index"))
geom_point(aes(colour
) plot.draw()
Here, a color scale is used for continuous variables, while discrete or categorical values are represented using discrete colors.
Note that some patient samples lack expression values, leading ggplot
to remove those points with missing values for ESR1 and GATA3.
Adding Shape
Let’s add shape to points.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1", shape = "factor(Survival_status)")) +
ggplot(data
geom_point()
) plot.draw()
Some aesthetics like shape can only be used with categorical variables:
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(shape = "Survival_time"))
geom_point(mapping
) plot.draw()
ValueError: Unrecognized marker style 0.0
The shape argument allows you to customize the appearance of all data points by assigning the symbol/letter associated with predefined shapes given here.
To use asterix instead of points in the plot:
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "*")
geom_point(shape
) plot.draw()
It would be useful to be able to change the shape of all the points. We can do so by setting the size to a single value rather than mapping it to one of the variables in the data set - this has to be done outside the aesthetic mappings (i.e. outside the aes()
bit) as above.
Instead of mapping an aesthetic property to a variable, you can set it to a single value by specifying it in the layer parameters (outside aes()
). We map an aesthetic to a variable (e.g., aes(shape = "Survival_status")
) or set it to a constant (e.g., shape = "*"
). If you want appearance to be governed by a variable in your data frame, put the specification inside aes()
; if you want to override the default size or colour, put the value outside of aes()
.
# size outside aes()
= (
plot1 = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "*")
geom_point(shape
)
plot1.draw()
# size inside aes()
= (
plot2 = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(shape = "Survival_status"))
geom_point(mapping
) plot2.draw()
The above plots are created with similar code, but have rather different outputs. The first plot sets the size to a value and the second plot maps (not sets) the size to the three-gene classifier variable.
It is usually preferable to use colours to distinguish between different categories but sometimes colour and shape are used together when we want to show which group a data point belongs to in two different categorical variables.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(colour = "factor(PAM50)", shape = "Survival_status"))
geom_point(mapping
) plot.draw()
Adding Size and Transparency
We can adjust the size and/or transparency of the points.
Let’s first increase the size of points.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(colour = "PAM50"), size = 2)
geom_point(mapping
) plot.draw()
Note that here we add the size argument outside of the the aesthetic mapping.
Size is not usually a good aesthetic to map to a variable and hence is not advised.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(colour = "PAM50", size = "ER_status"))
geom_point(mapping
) plot.draw()
/Users/sanduniprasadi/Library/r-miniconda-arm64/envs/r-reticulate/lib/python3.9/site-packages/plotnine/scales/scale_size.py:49: PlotnineWarning: Using size for a discrete variable is not advised.
Because this value is discrete, the default size scale uses evenly spaced sizes for points categorized on ER status.
Transparency can be useful when we have a large number of points as we can more easily tell when points are overlaid, but like size, it is not usually mapped to a variable and sits outside the aes()
.
Let’s change the transparency of points.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(colour = "3-gene_classifier"), alpha = 0.5)
geom_point(mapping
) plot.draw()
Adding Layers
We can add another layer to this plot using a different geometric representation (or geom_
function) we discussed previously.
Let’s add trend lines to this plot using the geom_smooth()
function which provide a summary of the data.
from plotnine import geom_smooth
= (
plot = metabric) + geom_point(mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(x = "GATA3", y = "ESR1"), method="lm")
geom_smooth(mapping
)
plot.draw() # Method can be one of ['lm', 'ols', 'wls', 'rlm', 'glm', 'gls', 'lowess', 'loess', 'mavg', 'gpr'] by default method is set to lm (linear model)
Note that the shaded area surrounding the black line represents the standard error bounds on the fitted model.
There is some annoying duplication of code used to create this plot. We’ve repeated the exact same aesthetic mapping for both geoms. We can avoid this by putting the mappings in the ggplot()
function instead.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data +
geom_point()
geom_smooth()
) plot.draw()
Geom layers specified earlier in the command are drawn first, preceding subsequent geom layers. The sequence of geom layers specified in the command determines their order of appearance in the plot.
If you switch the order of the geom_point()
and geom_smooth()
functions above, you’ll notice a change in the regression line. Specifically, the regression line will now be plotted underneath the points.
Let’s make the plot look a bit prettier by reducing the size of the points and making them transparent. We’re not mapping size or alpha to any variables, just setting them to constant values, and we only want these settings to apply to the points, so we set them inside geom_point()
.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = 1, alpha = 0.5) +
geom_point(size
geom_smooth()
) plot.draw()
Aesthetic mappings can be provided either in the initial ggplot()
call, in individual layers, or through a combination of both approaches. When there’s only one layer in the plot, the method used to specify aesthetics doesn’t impact the result.
# colour argument inside ggplot()
= (
plot1 = metabric, mapping = aes(x = "GATA3", y = "ESR1", colour = "ER_status")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size
geom_smooth()
)
plot1.draw()
# colour argument inside geom_point()
= (
plot2 = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = aes(colour = "ER_status"), size = 0.5, alpha = 0.5) +
geom_point(mapping
geom_smooth()
) plot2.draw()
In the left plot, since we specified the colour (i.e., colour = "ER_status"
) inside the ggplot()
function, the geom_smooth()
function will fit regression lines for each type of ER status and will have coloured regression lines as shown above. This is because, when aesthetic mappings are defined in ggplot()
, at the global level, they’re passed down to each of the subsequent geom layers of the plot.
If we want to add colour only to the points and fit a regression line across all points, we could specify the colour inside geom_point()
function (i.e., right plot).
Suppose you’ve spent a bit of time getting your scatter plot just right and decide to add another layer but you’re a bit worried about interfering with the code you so lovingly crafted, you can set the inherit.aes
option to False
and set the aesthetic mappings explicitly for your new layer.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1", colour = "ER_status")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size = "GATA3", y = "ESR1"), inherit_aes=False)
geom_smooth(aes(x
) plot.draw()
Coordinate Space
ggplot
automatically selects the scale and type of coordinate space for each axis. The majority of plots utilize Cartesian coordinate space, characterized by linear x and y scales.
from plotnine import lims, xlim,ylim, coord_cartesian
# assign a variable to the plot
= (
gata_esrp = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "ER_status"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour
geom_smooth()
) gata_esrp.draw()
We can change the axes limits as follows:
# change both x and y axes
= gata_esrp + lims(x = (0, 13), y = (0, 14))
t1
t1.draw()
# change x axis
= gata_esrp + xlim(5, 9)
t2
t2.draw()
# change x axis
= gata_esrp + ylim(0, 13)
t3 t3.draw()
Notice that we assigned a variable named gata_esrp
to our plot and modify it by adding labels. In ggplot
, you have the flexibility to assign a variable to plot and then modify it by adding layers to the plot. This approach allows you to progressively build up your visualization, incorporating various elements to convey the desired information effectively.
lims()/xlim()/ylim()
vs. coord_cartesian()
When you set the limits using any of the lims()/xlim()/ylim()
functions, it discards all data points outside the specified range. Consequently, the regression line is computed across the remaining data points. In contrast, coord_cartesian()
adjust limits without discarding the data, thus offering a visual zoom effect.
= (gata_esrp + ylim(7, 10))
p1
p1.draw()
= (gata_esrp + coord_cartesian(ylim = (7, 10)))
p2 p2.draw()
Axis Labels
By default, ggplot
use the column names specified inside the aes()
as the axis labels. We can change this using the xlab()
and ylab()
functions.
from plotnine import xlab, ylab
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "ER_status"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth() "GATA3 Expression") +
xlab("ESR1 Expression")
ylab(
) plot.draw()
Themes
Themes control the overall appearance of the plot, including background color, grid lines, axis labels, and text styles. ggplot offers several built-in themes, and you can also create custom themes to match your preferences or the requirements of your publication. The default theme has a grey background.
from plotnine import theme_bw
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "ER_status"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth()
theme_bw()
) plot.draw()
Try these themes yourselves: theme_classic()
, theme_dark()
, theme_grey()
(default), theme_light()
, theme_linedraw()
, theme_minimal()
, theme_void()
and theme_test()
.
Facets
To enhance readability and clarity, we can break the above plot into sub-plots, called faceting. Facets are commonly used to split a plot into multiple panels based on the values of one or more variables. This can be useful for exploring relationships in the data across different subsets or categories.
To do this, we specify the column name that will form each facet.
from plotnine import facet_wrap, facet_grid
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "PR_status"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth() "PR_status")
facet_wrap(
) plot.draw()
Note that the aesthetics and geoms including the regression line that were specified for the original plot, are applied to each of the facets.
Faceting is usually better than displaying groups using different colours when there are more than two or three groups when it can be difficult to really tell which points belong to each group. A case in point is for the three-gene classification in the GATA3 vs ESR1 scatter plot we created above. Let’s create a faceted version of that plot.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "3-gene_classifier"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth() "3-gene_classifier")
facet_wrap(
) plot.draw()
This helps explain why the function is called facet_wrap()
. When it has too many subplots to fit across the page, it wraps around to another row. We can control how many rows or columns to use with the nrow
and ncol
arguments.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "3-gene_classifier"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth() "3-gene_classifier", nrow = 1)
facet_wrap(
) plot.draw()
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = "3-gene_classifier"), size = 0.5, alpha = 0.5) +
geom_point(aes(colour +
geom_smooth() "3-gene_classifier", ncol = 2)
facet_wrap(
) plot.draw()
We can combine faceting on one variable with a colour aesthetic for another variable. For example, let’s show the tumour stage status (Neoplasm histologic grade) using faceting and the HER2 status using colours.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1", colour = "HER2_status")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size "Neoplasm_histologic_grade")
facet_wrap(
) plot.draw()
Instead of this we could facet on more than variable.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size "Neoplasm_histologic_grade", "HER2_status"])
facet_wrap([
) plot.draw()
Faceting on two variables is usually better done using the other faceting function, **facet_grid()
. Note that the variable expressions along the rows and the columns of the facet grid is set using rows=
and cols=
variables as follows:
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size "Neoplasm_histologic_grade", "HER2_status"])
facet_grid([
) plot.draw()
Again we can use colour aesthetics alongside faceting to add further information to our visualization.
= (
plot = metabric, mapping = aes(x = "GATA3", y = "ESR1", colour = "PAM50")) +
ggplot(data = 0.5, alpha = 0.5) +
geom_point(size "Neoplasm_histologic_grade", "HER2_status"])
facet_grid([
) plot.draw()
Bar chart
The metabric study redefined how we think about breast cancer by identifying and characterizing several new subtypes, referred to as integrative clusters. Let’s create a bar chart of the number of patients whose cancers fall within each subtype in the metabric cohort.
The geom_bar
is the geom used to plot bar charts. It requires a single aesthetic mapping of the categorical variable of interest to x
.
from plotnine import geom_bar
= (
plot = metabric) +
ggplot(data = "Integrative_cluster"))
geom_bar(aes(x
) plot.draw()
The dark grey bars are a big ugly - what if we want each bar to be a different colour?
= (
plot = metabric) +
ggplot(data = "Integrative_cluster", colour = "Integrative_cluster"))
geom_bar(aes(x
) plot.draw()
Colouring the edges wasn’t quite what we had in mind. Look at the help for geom_bar
to see what other aesthetic we should have used.
= (
plot = metabric) +
ggplot(data = "Integrative_cluster", fill = "Integrative_cluster"))
geom_bar(aes(x
) plot.draw()
What happens if we colour (fill) with something other than the integrative cluster?
= (
plot = metabric) +
ggplot(data = "Integrative_cluster", fill = "ER_status"))
geom_bar(aes(x
) plot.draw()
We get a stacked bar plot.
Note the similarity in what we did here to what we did with the scatter plot - there is a common grammar.
Let’s try another stacked bar plot, this time with a categorical variable with more than two categories.
# define 3-gene_classifier column as a categorical column
"3-gene_classifier"] = pd.Categorical(metabric["3-gene_classifier"],
metabric[= ['ER+/HER2- High Prolif', 'ER+/HER2- Low Prolif', 'ER-/HER2-', 'HER2+', 'Undefined'])
categories
# set missing values to the Undefined category defined above
"3-gene_classifier"] = metabric["3-gene_classifier"].fillna('Undefined')
metabric[
= (
plot = metabric) + geom_bar(aes(x = "Integrative_cluster", fill = '3-gene_classifier'))
ggplot(data
) plot.draw()
We can rearrange the three gene groups into adjacent (dodged) bars by specifying a different position within geom_bar()
:
= (
plot = metabric) +
ggplot(data = "Integrative_cluster", fill = "3-gene_classifier"), position = 'dodge')
geom_bar(aes(x
) plot.draw()
What if want all the bars to be the same colour but not dark grey, e.g. blue?
You can set the aesthetics to a fixed value but this needs to be outside the mapping, just like we did before for size and transparency in the scatter plots.
= (
plot = metabric) +
ggplot(data = "Integrative_cluster"), fill = "blue")
geom_bar(aes(x
) plot.draw()
Setting this inside the aes()
mapping told ggplot2 to map the colour aesthetic to some variable in the data frame, one that doesn’t really exist.
You may have noticed that ggplot
didn’t just plot values from our data set but had to do some calculation first for the bar chart, i.e. it had to sum the number of observations in each category.
Each geom has a statistical transformation. In the case of the scatter plot, geom_point
uses the “identity” transformation which means just use the values as they are (i.e. not really a transformation at all). The statistical transformation for geom_bar
is “count”, which means it will count the number of observations for each category in the variable mapped to the x aesthetic.
You can see which statistical transformation is being used by a geom by looking at the stat
argument in the help page for that geom.
There are some circumstances where you’d want to change the stat
, for example if we already had count values in our table.
# the previous plot
= (
plot1 = metabric) +
ggplot(data = "Integrative_cluster"))
geom_bar(aes(x
)
plot1.draw()
# Count the occurrences of each category in the 'Integrative_cluster' column
= metabric["Integrative_cluster"].value_counts()
counts # Convert the series to a DataFrame with index as a column
= counts.reset_index()
counts_df # same plot after computing counts and using the identity stat
= (
plot2 = counts_df) +
ggplot(data = "Integrative_cluster", y = "count"), stat = "identity")
geom_bar(aes(x
) plot2.draw()
Box plot
Box plots (or box & whisker plots) are a particular favourite seen in many seminars and papers. Box plots summarize the distribution of a set of values by displaying the minimum and maximum values, the median (i.e. middle-ranked value), and the range of the middle 50% of values (inter-quartile range). The whisker line extending above and below the IQR box define Q3 + (1.5 x IQR), and Q1 - (1.5 x IQR) respectively.
To create a box plot from Metabric dataset:
from plotnine import geom_boxplot, geom_jitter
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3")) +
ggplot(data
geom_boxplot()
) plot.draw()
See geom_boxplot
help to explain how the box and whiskers are constructed and how it decides which points are outliers and should be displayed as points.
How about adding another layer to display all the points?
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3")) +
ggplot(data +
geom_boxplot()
geom_point()
) plot.draw()
Ideally, we’d like these points to be spread out a bit. The help page of geom_point
fucntion points to geom_jitter
as more suitable when one of the variables is categorical.
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3")) +
ggplot(data +
geom_boxplot()
geom_jitter()
) plot.draw()
Well, that’s a bit of a mess. We can bring the geom_boxplot()
layer forward:
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3")) +
ggplot(data +
geom_jitter() = 0.5)
geom_boxplot(alpha
) plot.draw()
Still not the best plot. We can reduce the spread or jitter and make the points smaller and transparent:
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3")) +
ggplot(data +
geom_boxplot() = 0.3, size = 0.5, alpha = 0.25)
geom_jitter(width
) plot.draw()
Displaying points in this way makes much more sense when we only have a few observations and where the box plot masks the fact, perhaps giving the false impression that the sample size is larger than it actually is. Here it makes less sense as we have very many observations.
Let’s try a colour aesthetic to also look at how estrogen receptor expression differs between HER2 positive and negative tumours.
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3", colour = "HER2_status")) +
ggplot(data
geom_boxplot()
) plot.draw()
Violin plot
A violin plot is used to visualize the distribution of a numeric variable across different categories. It combines aspects of a box plot and a kernel density plot.
The width of the violin at any given point represents the density of data at that point. Wider sections indicate a higher density of data points, while narrower sections indicate lower density. By default, violin plots are symmetric.
from plotnine import geom_violin, position_dodge
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3", colour = "HER2_status")) +
ggplot(data
geom_violin()
) plot.draw()
Inside each violin plot, a box plot is often included, showing additional summary statistics such as the median, quartiles, and potential outliers. This helps provide a quick overview of the central tendency and spread of the data within each category.
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3", colour = "HER2_status")) +
ggplot(data +
geom_violin() = 0.8, alpha = 0.4)
geom_boxplot(width
) plot.draw()
In the above plot, the violin plots and box plots are misaligned. You can read the cause of this here.
To align them, we can use the position_dodge()
function to manually adjusting the horizontal position as follows.
= (
plot = metabric, mapping = aes(x = "ER_status", y = "GATA3", colour = "HER2_status")) +
ggplot(data = position_dodge(0.8)) +
geom_violin(position = 0.8, alpha = 0.4)
geom_boxplot(width
) plot.draw()
Histogram
The geom for creating histograms is, rather unsurprisingly, geom_histogram()
.
from plotnine import geom_histogram
= (
plot = metabric) +
ggplot(data = "Age_at_diagnosis"))
geom_histogram(aes(x
) plot.draw()
/Users/sanduniprasadi/Library/r-miniconda-arm64/envs/r-reticulate/lib/python3.9/site-packages/plotnine/stats/stat_bin.py:109: PlotnineWarning: 'stat_bin()' using 'bins = 24'. Pick better value with 'binwidth'.
The warning message hints at picking a more optimal number of bins by specifying the binwidth
argument.
= (
plot = metabric) +
ggplot(data = "Age_at_diagnosis"), binwidth = 5)
geom_histogram(aes(x
) plot.draw()
Or we can set the number of bins.
= (
plot = metabric) +
ggplot(data = "Age_at_diagnosis"), bins = 20)
geom_histogram(aes(x
) plot.draw()
These histograms are not very pleasing, aesthetically speaking - how about some better aesthetics?
= (
plot = metabric) +
ggplot(data = "Age_at_diagnosis"), bins = 20, colour = "darkblue", fill = "grey")
geom_histogram(aes(x
) plot.draw()
Density plot
Density plots are used to visualize the distribution of a continuous variable in a dataset. These are essentially smoothed histograms, where the area under the curve for each sub-group will sum to 1. This allows us to compare sub-groups of different size.
from plotnine import geom_density
= (
plot = metabric) +
ggplot(data = "Age_at_diagnosis", colour = "Integrative_cluster"))
geom_density(aes(x
) plot.draw()
Categorical variables
Several of the variables in the Metabric data set are categorical. Some of these have been read into Python as character types (e.g. the three gene classifier), other as numerical values (e.g. tumour stage). We also have some binary variables that are essentially categorical variables but with only 2 possible values (e.g. ER status).
In many of the plots given above, ggplot
has treated character variables as categorical in situations where a categorical variable is expected. For example, when we displayed points on a scatter plot using different colours for each three gene classification, or when we created separate box plots in the same graph for ER positive and negative patients.
But what about when our categorical variable has been read into Python as a continuous variable, e.g. Tumour_stage
, which is read in as a double type.
= (
plot = metabric) +
ggplot(data = "GATA3", y = "ESR1", colour = "Tumour_stage"))
geom_point(aes(x
) plot.draw()
metabric.Tumour_stage.unique()
array([ 2., 1., 4., 3., nan, 0.])
Tumour stage has only 5 discrete states but ggplot
doesn’t know these are supposed to be a restricted set of values and has used a colour scale to show them as if they were continuous. We need to tell Python that these are categorical (or factors).
Let’s convert our tumour stage variable to a factor using the Categorical()
function.
"Tumour_stage"] = pd.Categorical(metabric["Tumour_stage"])
metabric[# or directly convert the type to category
# metabric["Tumour_stage"] = metabric["Tumour_stage"].astype("category")
"Tumour_stage", "Patient_ID"]].head() metabric[[
Tumour_stage | Patient_ID | |
---|---|---|
0 | 2.0 | MB-0000 |
1 | 1.0 | MB-0002 |
2 | 2.0 | MB-0005 |
3 | 2.0 | MB-0006 |
4 | 2.0 | MB-0008 |
Python actually stores categorical variables as integers but with some additional metadata about which of the integer values, or ‘categories’, corresponds to each category.
type(metabric["Tumour_stage"])
"Tumour_stage"].cat.categories metabric[
Index([0.0, 1.0, 2.0, 3.0, 4.0], dtype='float64')
= (
plot = metabric) +
ggplot(data = "GATA3", y = "ESR1", colour = "Tumour_stage"))
geom_point(aes(x
) plot.draw()
In this case the order of the categories makes sense but for other variables you may wish for more control over the ordering. Take the integrative cluster variable for example. We created a bar plot of the numbers of patients in the Metabric cohort within each integrative cluster. Did you notice the ordering of the clusters? 10 came just after 1 and before 2. That looked a bit odd as we’d have naturally expected it to come last of all. Python, on the other hand, is treating this vector as a character vector (mainly because of the ‘ER-’ and ‘ER+’ subtypes of cluster 4, and sorts the values into alphanumerical order.
"Integrative_cluster"] = pd.Categorical(metabric["Integrative_cluster"])
metabric["Integrative_cluster"].cat.categories metabric[
Index(['1', '10', '2', '3', '4ER+', '4ER-', '5', '6', '7', '8', '9'], dtype='object')
We can create a factor using the Categorical()
function and specify the categories using the categories
argument.
"Integrative_cluster"] = pd.Categorical(metabric["Integrative_cluster"],
metabric[= ["1", "2", "3", "4ER-", "4ER+", "5", "6", "7", "8", "9", "10"])
categories "Integrative_cluster"].cat.categories metabric[
Index(['1', '2', '3', '4ER-', '4ER+', '5', '6', '7', '8', '9', '10'], dtype='object')
= (
plot = metabric) +
ggplot(data = "Integrative_cluster", fill = "Integrative_cluster"))
geom_bar(aes(x
) plot.draw()
Line plot
A line plot is used to display the trend or pattern in data over a continuous range of values, typically along the x-axis (horizontal axis).
Before we create a line plot, let’s start by reading a subset of cancer_mort dataset using the read_csv()
function:
# first read the dataset
= pd.read_csv("data/Australian_Cancer_Incidence_and_Mortality.csv")
cancer_mort_full # lets consider the rows with cancer types that starts with B letters only.
# this is done for illustartion purposes.
= cancer_mort_full[cancer_mort_full.Cancer_Type.str.contains('^B[a-z]+')] cancer_mort
Next, we filter the cancer_mort data frame to plot only the counts for the female patients in the age group 55-59 and are categorized as moratality cases.
# define a new subset from cancer_mort dataset
= cancer_mort.query("Age == '55-59' and Type == 'Mortality' and Sex == 'Female'") cancer_mort_55
from plotnine import geom_line
= (
plot = cancer_mort_55, mapping = aes(x = "Year", y = "Count")) +
ggplot(data = "Cancer_Type"))
geom_line(aes(colour
) plot.draw()
Another aesthetic available for geom_line
is linetype.
= (
cancer_count = cancer_mort_55, mapping = aes(x = "Year", y = "Count")) +
ggplot(data = "Cancer_Type"))
geom_line(aes(linetype
) cancer_count.draw()
Saving plot images
Use ggsave()
to save a plot.
"Cancer_type_vs_count.png") cancer_count.save(
You can alter the width and height of the plot and can change the image file type.
"Cancer_type_vs_count.pdf", width = 20, height = 12, units = "cm") cancer_count.save(
Customizing Plots - continued
Scales
One of the components of the plot is called scales
. ggplot
automatically adds default scales behind the scene equivalent to the following:
from plotnine import geom_smooth, scale_x_continuous, scale_y_continuous, scale_colour_discrete
= (
plot
ggplot(= metabric,
data = aes(x = "Nottingham_prognostic_index", y = "ESR1", colour = "ER_status")) +
mapping = 0.6, alpha = 0.5) +
geom_point(size = "lm") +
geom_smooth(method +
scale_x_continuous() +
scale_y_continuous()
scale_colour_discrete()
) plot.draw()
Note that we have three aesthetics and ggplot adds a scale for each.
plot.mapping
{'x': 'Nottingham_prognostic_index', 'y': 'ESR1', 'color': 'ER_status'}
The x and y variables (Nottingham_prognostic_index
and ESR1
) are continuous so ggplot
adds a continuous scale for each. ER_status
is a discrete variable in this case so ggplot
adds a discrete scale for colour.
Generalizing, the scales that are required follow the naming scheme:
<NAME_OF_AESTHETIC>_<NAME_OF_SCALE> scale_
Look at the help page for scale_y_continuous
to see what we can change about the y-axis scale (To view the help page run the command: help(plotnine.scale_y_continuous)
).
First we’ll change the breaks, i.e. where ggplot
puts ticks and numeric labels, on the y axis.
= (
scat_plot
ggplot(= metabric,
data = aes(x = "Nottingham_prognostic_index", y = "ESR1", colour = "ER_status")) +
mapping = 0.6, alpha = 0.5) +
geom_point(size = "lm")
geom_smooth(method
)
= (
plot + scale_y_continuous(breaks = np.arange(5, 15, 2.5).tolist())
scat_plot
) plot.draw()
arange()
is a useful function for generating regular sequences of numbers. In this case we wanted numbers from 5 to 15 going up in steps of 2.5.
5, 15, 2.5) np.arange(
array([ 5. , 7.5, 10. , 12.5])
We could do the same thing for the x axis using scale_x_continuous()
.
We can also adjust the extents of the x or y axis.
= (
plot +
scat_plot = np.arange(5, 15, 2.5).tolist(), limits = (4, 12))
scale_y_continuous(breaks
) plot.draw()
/Users/sanduniprasadi/Library/r-miniconda-arm64/envs/r-reticulate/lib/python3.9/site-packages/plotnine/layer.py:364: PlotnineWarning: geom_point : Removed 160 rows containing missing values.
Here, just for demonstration purposes, we set the upper limit to be less than the largest values of ESR1 expression and ggplot
warned us that some rows have been removed from the plot.
We can change the minor breaks, e.g. to add more lines that act as guides. These are shown as thin white lines when using the default theme.
= (
plot +
scat_plot
scale_y_continuous(= np.arange(5, 12.5, 2.5).tolist(),
breaks = (5, 13.5),
limits = np.arange(5, 13.5, 0.5).tolist())
minor_breaks
) plot.draw()
Or we can remove the minor breaks entirely.
= (
plot +
scat_plot
scale_y_continuous(= np.arange(6, 14, 2).tolist(),
breaks = (5, 13.5),
limits = False)
minor_breaks
) plot.draw()
Similarly we could remove all breaks entirely.
= (
plot + scale_y_continuous(breaks = False)
scat_plot
) plot.draw()
A more typical scenario would be to keep the breaks, because we want to display the ticks and their lables, but remove the grid lines. Somewhat confusingly the position of grid lines are controlled by a scale but preventing these from being displayed requires changing the theme. The theme controls the way in which non-data components are displayed – we’ll look at how these can be customized later. For now, though, here’s an example of turning off the display of all grid lines for major and minor breaks for both axes.
from plotnine import theme, element_blank
= (
plot +
scat_plot = np.arange(4, 14, 2), limits = (4, 14)) +
scale_y_continuous(breaks = element_blank())
theme(panel_grid
) plot.draw()
By default, the scales are expanded by 5% of the range on either side. We can add or reduce the space as follows.
= (
plot +
scat_plot = (0.01, 0)) +
scale_x_continuous(expand = (0.25, 0))
scale_y_continuous(expand
) plot.draw()
Here expand =
argument refers to multiplicative and additive expansion constants that determine how the scale is expanded. If specified must be of length 2 or 4. Specifically the values are in this order:
(mul, add)
(mul_low, add_low, mul_high, add_high)
For example,
(0, 0)
: Do not expand.(0, 1)
: Expand lower and upper limits by 1 unit.(1, 0)
: Expand lower and upper limits by 100%.(0, 0, 0, 0)
: Do not expand, as(0, 0)
.(0, 0, 0, 1)
: Expand upper limit by 1 unit.(0, 1, 0.1, 0)
: Expand lower limit by 1 unit and upper limit by 10%.(0, 0, 0.1, 2)
: Expand upper limit by 10% plus 2 units.
Here we only added 1% (0.01) of the range of NPI values on either side along the x axis but we added 25% (0.25) of the range of ESR1 expression on either side along the y axis.
Colours
The colour asthetic is used with a categorical variable, ER_status
, in the scatter plots we’ve been customizing. The default colour scale used by ggplot
for categorical variables is scale_colour_discrete
. We can manually set the colours we wish to use using scale_colour_manual
instead.
from plotnine import scale_colour_manual
= (
plot
ggplot(= metabric,
data = aes(x = "Nottingham_prognostic_index", y = "ESR1", colour = "ER_status")) +
mapping = 0.6, alpha = 0.5) +
geom_point(size = "lm") + scale_colour_manual(values = ["dodgerblue", "firebrick"])
geom_smooth(method
) plot.draw()
The following figure displays the names of the colors available to use in the scale_colour_manual()
function in plotnine
. These color names can be directly used to customize the appearance of your plots.
To view the list of available color names, you can also refer to the matplotlib color documentation, as plotnine uses matplotlib’s color names for setting custom colors in plots.
Setting colours manually is ok when we only have two or three categories but when we have a larger number it would be handy to be able to choose from a selection of carefully-constructed colour palettes. Helpfully, ggplot
provides access to the ColorBrewer palettes through the functions scale_colour_brewer()
and scale_fill_brewer()
.
from plotnine import scale_colour_brewer
= (
scat_plot
ggplot(= metabric,
data = aes(x = "Nottingham_prognostic_index", y = "ESR1", colour = "3-gene_classifier")) +
mapping = 0.6, alpha = 0.5, na_rm = True) +
geom_point(size = "lm") +
geom_smooth(method type = "qualitative", palette = "Set1")
scale_colour_brewer(
) scat_plot.draw()
Look at the help page for scale_colour_brewer
to see what other colour palettes are available and visit the ColorBrewer website to see what these look like.
Interestingly, you can set other attributes other than just the colours at the same time.
# remove legend title for colour now that the labels are self-explanatory
from plotnine import labs
= (
scat_plot
ggplot(= metabric,
data = aes(x = "Nottingham_prognostic_index", y = "ESR1", colour = "ER_status")) +
mapping = 0.6, alpha = 0.5) +
geom_point(size = "lm") +
geom_smooth(method = ["dodgerblue", "firebrick"], labels = ["ER-negative", "ER-positive"]) +
scale_colour_manual(values = '')
labs(colour
) scat_plot.draw()
We have applied our own set of mappings from categories in the data to aesthetic values.
For continuous variables we may wish to be able to change the colours used in the colour gradient. To demonstrate this we’ll use the Nottingham prognostic index (NPI) values to colour points in the scatter plot of ESR1 vs GATA3 expression on a continuous scale.
= (
plot
ggplot(= metabric,
data = aes(x = "GATA3", y = "ESR1", colour = "Nottingham_prognostic_index")) +
mapping = 0.5, na_rm = True)
geom_point(size
) plot.draw()
Higher NPI scores correspond to worse prognosis and lower chance of 5 year survival. We’ll emphasize those points on the scatter plot by adjusting our colour scale.
from plotnine import scale_colour_gradient, scale_colour_gradient2
= (
plot
ggplot(= metabric,
data = aes(x = "GATA3", y = "ESR1", colour = "Nottingham_prognostic_index")) +
mapping = 0.75, na_rm = True) +
geom_point(size = "white", high = "firebrick")
scale_colour_gradient(low
) plot.draw()
In some cases it might make sense to specify two colour gradients either side of a mid-point.
= (
plot
ggplot(= metabric,
data = aes(x = "GATA3", y = "ESR1", colour = "Nottingham_prognostic_index")) +
mapping = 0.75, na_rm = True) +
geom_point(size = "dodgerblue", mid = "#808080", high = "firebrick", midpoint = 4.5)
scale_colour_gradient2(low
) plot.draw()
As before we can override the default labels and other aspects of the colour scale within the scale function.
= (
plot
ggplot(= metabric,
data = aes(x = "GATA3", y = "ESR1", colour = "Nottingham_prognostic_index")) +
mapping = 0.75, na_rm = True) +
geom_point(size
scale_colour_gradient(= "lightblue", high = "darkblue", name = "NPI Values",
low = np.arange(2,7), limits = (1.5, 6.5))
breaks
) plot.draw()
Themes
Themes can be used to customize non-data components of a plot. Let’s create a plot showing the expression of estrogen receptor alpha (ESR1) for each of the Integrative cluster breast cancer subtypes.
# plot the ESR1 expression for each integrative cluster
= (
intclust_plot = metabric) +
ggplot(data = "Integrative_cluster", y = "ESR1", fill = "Integrative_cluster")) +
geom_boxplot(aes(x = "Integrative cluster", y = "ESR1 expression")
labs(x
) intclust_plot.draw()
The default theme has the characteristic grey background which isn’t particularly suitable for printing on paper. We can change to one of a number of alternative themes available in the ggplot2 package, e.g. the black and white theme.
from plotnine import theme_bw
= (intclust_plot + theme_bw())
plot plot.draw()
Each of these themes is really just a collection of attributes relating to how various non-data elements of the plot will be displayed. We can override any of these individual settings using the theme()
function. A look at the help page (help(plotnine.theme)
) shows that there are a very large number of settings that you can change. The following example demonstrates a few of these.
= (
plot +
intclust_plot +
theme_bw()
theme(= element_blank(),
panel_grid_major_x = element_blank(),
axis_ticks_major_x = "none")
legend_position
) plot.draw()
Here’s another example that also involves customizing the labels, scales and colours.
from plotnine import scale_fill_manual, element_line, element_text
= (
plot = metabric) +
ggplot(data = "3-gene_classifier", fill = "ER_status")) +
geom_bar(aes(x = (0, 700), breaks = np.arange(0, 800, 100), expand = (0,0)) +
scale_y_continuous(limits = ["firebrick", "dodgerblue"]) +
scale_fill_manual(values = '', y = "samples", fill = "ER status") +
labs(x +
theme_bw()
theme(= element_blank(),
panel_border = element_blank(),
panel_grid = element_blank(),
axis_ticks_major_x = element_text(angle = 45, hjust = 1, vjust = 1),
axis_text_x = element_line(),
axis_line_y = 8,
axis_ticks_length = "bottom")
legend_position
) plot.draw()
Position adjustments
All geoms in ggplot
have a position adjustment that can be set using the position
argument. This has different effects for different types of plot but essentially this resolves how overlapping geoms are displayed.
For example, let’s consider the stacked bar plot we created earlier showing the numbers of patients in each of the 3-gene classifications subdivided by ER status. The default position value for geom_bar()
is “stack” which is why the plot is shown as a stacked bar chart. An alternative way of representing these data would be to show separate bars for each ER status side-by-side by setting position = "dodge"
.
= (
plot = metabric) +
ggplot(data = "3-gene_classifier", fill = "ER_status"), position = "dodge") +
geom_bar(aes(x = (0, 700), breaks = np.arange(0, 800, 100), expand = (0,0)) +
scale_y_continuous(limits = ["firebrick", "dodgerblue"]) +
scale_fill_manual(values = '', y = "samples", fill = "ER status") +
labs(x +
theme_bw()
theme(= element_blank(),
panel_border = element_blank(),
panel_grid = element_blank(),
axis_ticks_major_x = element_text(angle = 45, hjust = 1, vjust = 1),
axis_text_x = element_line(), axis_ticks_length = 8)
axis_line_y
) plot.draw()
Another position adjustment we’ve come across is geom_jitter()
, which is just a convenient shortcut for geom_point(position = "jitter")
. A variation on this, position_jitterdodge()
, comes in handy when we are overlaying points on top of a box plot. We show an example of just such a plot in which first use postion = "jitter"
.
from plotnine import scale_color_brewer, theme_minimal
= (
plot = metabric, mapping = aes(x = "3-gene_classifier", y = "ESR1", colour = "PR_status")) +
ggplot(data +
geom_boxplot() = "jitter", size = 0.5, alpha = 0.3) +
geom_point(position = "3-gene classification", y = "ESR1 expression", colour = "PR status") +
labs(x type = "qualitative", palette = "Set1") +
scale_color_brewer(+
theme_minimal()
theme(= element_blank(),
panel_grid_major_x = element_text(angle = 45, hjust = 1, vjust = 1),
axis_text_x = element_blank())
axis_ticks_major_x
) plot.draw()
The PR-negative and PR-positive points have distinct colours but are overlapping in a way that is aesthetically displeasing. What we want is for the points to have both jitter and to be dodged in the same way as the boxes. With position_jitterdodge()
we get a better looking plot.
from plotnine import position_jitterdodge
= (
plot = metabric, mapping = aes(x = "3-gene_classifier", y = "ESR1", colour = "PR_status")) +
ggplot(data +
geom_boxplot() = position_jitterdodge(), size = 0.5, alpha = 0.3) +
geom_point(position = "3-gene classification", y = "ESR1 expression", colour = "PR status") +
labs(x type = "qualitative", palette = "Set1") +
scale_color_brewer(+
theme_minimal()
theme(= element_blank(),
panel_grid_major_x = element_text(angle = 45, hjust = 1, vjust = 1),
axis_text_x = element_blank())
axis_ticks_major_x
) plot.draw()
This concludes the visualization section and the Introduction to Python materials. By now, you should be able to pre-process data, analyze it to uncover insights, and finally create aesthetically pleasing, publication-worthy plots. These skills will equip you with a solid foundation in data manipulation and visualization, enabling you to communicate your findings effectively through both analysis and visual storytelling.