Geoms¶
geom_pointdensity¶
- class plotnine_extra.geom_pointdensity(mapping=None, data=None, **kwargs)[source]¶
Bases:
plotnine.geom_pointScatterplot with density estimation at each point
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 `1`{.py} color `’black’`{.py} fill `None`{.py} group shape `’o’`{.py} size `1.5`{.py} stroke `0.5`{.py}
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
stat (str | stat, default="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 | position, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
inherit_aes (bool, default=True) – If `False`{.py}, overrides the default aesthetics.
show_legend (bool | dict, default=None) – Whether this layer should be included in the legends. None`{.py} the default, includes any aesthetics that are mapped. If a [](:class:`bool), False`{.py} never includes and `True`{.py} always includes. A [](:class:`dict) can be used to exclude specific aesthetis of the layer from showing in the legend. e.g `show_legend={‘color’: False}`{.py}, any other aesthetic are included by default.
raster (bool, default=False) – If True, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
**kwargs (Any) – Aesthetics or parameters used by the stat.
- DEFAULT_PARAMS = {'na_rm': False, 'position': 'identity', 'stat': 'pointdensity'}¶
Required parameters for the geom
geom_spoke¶
- class plotnine_extra.geom_spoke(mapping=None, data=None, **kwargs)[source]¶
Bases:
plotnine.geom_segmentLine segment parameterised by location, direction and distance
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, 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 `1`{.py} color `’black’`{.py} group linetype `’solid’`{.py} size `0.5`{.py}
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
stat (str | stat, default="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 | position, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
inherit_aes (bool, default=True) – If `False`{.py}, overrides the default aesthetics.
show_legend (bool | dict, default=None) – Whether this layer should be included in the legends. None`{.py} the default, includes any aesthetics that are mapped. If a [](:class:`bool), False`{.py} never includes and `True`{.py} always includes. A [](:class:`dict) can be used to exclude specific aesthetis of the layer from showing in the legend. e.g `show_legend={‘color’: False}`{.py}, any other aesthetic are included by default.
raster (bool, default=False) – If True, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
**kwargs (Any) – Aesthetics or parameters used by the stat.
See also
plotnine.geom_segmentFor documentation of extra parameters.
- REQUIRED_AES = {'angle', 'radius', 'x', 'y'}¶
Required aesthetics for the geom
- setup_data(data)[source]¶
Modify the data before drawing takes place
This function is called before position adjustments are done. It is used by geoms to create the final aesthetics used for drawing. The base class method does nothing, geoms can override this method for two reasons:
The stat does not create all the aesthetics (usually position aesthetics) required for drawing the geom, but those aesthetics can be computed from the available data. For example [](~plotnine.geoms.geom_boxplot) and [](~plotnine.geoms.geom_violin).
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 [](~plotnine.geoms.geom_tile) and [](~plotnine.geoms.geom_area).
- Parameters:
data (pd.DataFrame) – Data used for drawing the geom.
- Returns:
Data used for drawing the geom.
- Return type:
pd.DataFrame
geom_bracket¶
- class plotnine_extra.geom_bracket(mapping=None, data=None, **kwargs)[source]¶
Bases:
geomDraw significance brackets with labels
Draws a U-shaped bracket (two vertical tips connected by a horizontal bar) with a centered text label, typically used for significance annotations.
Usage
- Parameters:
mapping (plotnine.aes, default=None) –
Aesthetic mappings created with [aes](
plotnine.aes). If specified and `inherit_aes=True`{.py}, it is combined with the default mapping for the plot. You must supply mapping if there is no plot mapping.Aesthetic Default value
———– ————— label xmax xmin y alpha `1`{.py} color `’black’`{.py} group
The bold aesthetics are required.
data (DataFrame, default=None) – The data to be displayed in this layer. If `None`{.py}, the data from from the `ggplot()`{.py} call is used. If specified, it overrides the data from the `ggplot()`{.py} call.
stat (str | stat, default="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 | position, default="identity") – Position adjustment. If it is a string, it must be registered and known to Plotnine.
na_rm (bool, default=False) – If `False`{.py}, removes missing values with a warning. If `True`{.py} silently removes missing values.
inherit_aes (bool, default=True) – If `False`{.py}, overrides the default aesthetics.
show_legend (bool | dict, default=None) – Whether this layer should be included in the legends. None`{.py} the default, includes any aesthetics that are mapped. If a [](:class:`bool), False`{.py} never includes and `True`{.py} always includes. A [](:class:`dict) can be used to exclude specific aesthetis of the layer from showing in the legend. e.g `show_legend={‘color’: False}`{.py}, any other aesthetic are included by default.
raster (bool, default=False) – If True, draw onto this layer a raster (bitmap) object even ifthe final image is in vector format.
tip_length (float, default=0.02) – Length of the bracket tips as a fraction of the y data range.
bracket_nudge_y (float, default=0) – Vertical offset for the bracket.
label_size (float, default=8) – Font size for the label text.
vjust (float, default=0) – Vertical justification of the label relative to the bracket.
bracket (bool, default=True) – If
False, suppress the bracket line and draw only the label. Mirrors thebracketparameter ofggcompare::geom_bracket.**kwargs (Any) – Aesthetics or parameters used by the stat.
- REQUIRED_AES = {'label', 'xmax', 'xmin', 'y'}¶
Required aesthetics for the geom
- DEFAULT_AES = {'alpha': 1, 'color': 'black'}¶
Default aesthetics for the geom
- DEFAULT_PARAMS = {'bracket': True, 'bracket_nudge_y': 0, 'label_size': 8, 'na_rm': False, 'position': 'identity', 'stat': 'identity', 'tip_length': 0.02, 'vjust': 0}¶
Required parameters for the geom
- static draw_legend(data, da, lyr)¶
Brackets carry no useful legend, return an empty area.
- Parameters:
data (pd.Series)
da (DrawingArea)
- Return type:
DrawingArea
- static draw_group(data, panel_params, coord, ax, params)[source]¶
Plot data belonging to a group.
- Parameters:
data (pd.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:
`python "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.
annotation_stripes¶
- class plotnine_extra.annotation_stripes(fill=('#AAAAAA', '#CCCCCC'), fill_range='auto', direction='vertical', extend=(0, 1), **kwargs)[source]¶
Bases:
plotnine.annotateAlternating stripes, centered around each label.
Useful as a background for geom_jitter.
- Parameters:
fill (Sequence[str]) – List of colors for the strips.
fill_range (Literal['auto', 'cycle', 'no', 'nocycle']) –
How to fill stripes beyond the range of scale:
```python “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
direction (Literal['horizontal', 'vertical']) – Orientation of the stripes
extend (tuple[float, float]) – Range of the stripes. The default is (0, 1), top to bottom. The values should be in the range [0, 1].
**kwargs (Any) – Other aesthetic parameters for the rectangular stripes. They include; alpha, color, linetype, and size.