Themes

Theme Elements

element_markdown

class plotnine_extra.element_markdown(family=None, style=None, weight=None, color=None, size=None, ha=None, va=None, rotation=None, linespacing=None, backgroundcolor=None, margin=None, face=None, **kwargs)[source]

Bases: plotnine.element_text

Theme element for rendering text with markdown-style parameters

A convenience wrapper around element_text that accepts extra styling shortcuts inspired by R’s ggtext::element_markdown.

Parameters:
  • family (str) – Font family.

  • style (str) – Font style ("normal", "italic").

  • weight (str | int) – Font weight ("normal", "bold", etc.).

  • color (str | tuple) – Text colour.

  • size (float) – Font size.

  • ha (str) – Horizontal alignment.

  • va (str) – Vertical alignment.

  • rotation (float) – Rotation angle in degrees.

  • linespacing (float) – Line spacing multiplier.

  • backgroundcolor (str | tuple) – Background colour behind the text.

  • margin (dict | Margin) – Margin around the text.

  • face (str) – Convenience shortcut: "bold", "italic", "bold.italic", or "plain".

  • **kwargs – Extra matplotlib text properties.

Notes

R’s element_markdown can render arbitrary inline HTML/CSS inside plot titles and labels. matplotlib does not support this; only whole-element properties (colour, weight, style, background) are available.

element_textbox_simple

class plotnine_extra.element_textbox_simple(family=None, style=None, weight=None, color=None, size=None, ha='left', va='top', linespacing=1.2, backgroundcolor=None, margin=None, face=None, **kwargs)[source]

Bases: plotnine.element_text

Theme element for text rendered inside a box

A convenience wrapper that sets sensible defaults for boxed text (transparent fill, no border, full width). Inspired by R’s ggtext::element_textbox_simple.

Parameters:
  • family (str) – Font family.

  • style (str) – Font style.

  • weight (str | int) – Font weight.

  • color (str | tuple) – Text colour.

  • size (float) – Font size.

  • ha (str) – Horizontal alignment.

  • va (str) – Vertical alignment.

  • linespacing (float) – Line spacing (default 1.2).

  • backgroundcolor (str | tuple) – Background colour.

  • margin (dict | Margin) – Margin around the text.

  • face (str) – Convenience shortcut: "bold", "italic", "bold.italic", or "plain".

  • **kwargs – Extra matplotlib text properties.

Notes

In R, element_textbox_simple renders a word-wrapped text box. In plotnine, word wrapping must be done at the data level (e.g. with textwrap.fill). This element applies the visual styling.

Publication Themes

theme_pubr

class plotnine_extra.theme_pubr(base_size=12, base_family='')[source]

Bases: plotnine.theme_bw

Publication-ready theme inspired by ggpubr.

A clean theme with no grid lines, axis lines on the bottom and left, and a white background. Suitable for most journal submissions.

Parameters:
  • base_size (float) – Base font size in points.

  • base_family (str) – Base font family.

theme_clean

class plotnine_extra.theme_clean(base_size=14, base_family='')[source]

Bases: plotnine.theme_minimal

Minimal clean theme for presentations.

Light grid lines, no axis lines, generous spacing. Good for slides and posters.

Parameters:
  • base_size (float) – Base font size in points.

  • base_family (str) – Base font family.

theme_scientific

class plotnine_extra.theme_scientific(base_size=10, base_family='')[source]

Bases: plotnine.theme_bw

Theme for scientific figures.

Thin axis lines, minimal decoration, serif-friendly. Follows common scientific journal style guidelines.

Parameters:
  • base_size (float) – Base font size in points.

  • base_family (str) – Base font family.

theme_nature

class plotnine_extra.theme_nature(base_size=7, base_family='Arial')[source]

Bases: plotnine.theme_bw

Theme approximating Nature journal style.

Small font sizes, no grid, thin black axis lines, and minimal decoration.

Parameters:
  • base_size (float) – Base font size in points.

  • base_family (str) – Base font family.

theme_classic2

class plotnine_extra.theme_classic2(base_size=12, base_family='')[source]

Bases: plotnine.theme_bw

A classic theme with axis lines and no panel border.

Port of ggpubr::theme_classic2: white background, no grid, axis lines on the left and bottom only.

Parameters:

theme_pubclean

class plotnine_extra.theme_pubclean(base_size=12, base_family='', flip=False)[source]

Bases: plotnine.theme_bw

Port of ggpubr::theme_pubclean.

A minimal theme with horizontal grid lines and a clean background. Useful for bar / dot charts.

Parameters:

theme_cleveland

class plotnine_extra.theme_cleveland(base_size=12, base_family='', flip=True)[source]

Bases: plotnine.theme_bw

Port of ggpubr::theme_cleveland.

A theme suited to Cleveland-style dot plots, with horizontal grid lines and no axis ticks on the y-axis.

Parameters:

theme_transparent

class plotnine_extra.theme_transparent[source]

Bases: plotnine.theme

Port of ggpubr::theme_transparent.

Sets every panel / plot / legend background element to transparent. Useful when overlaying plots on slides.

theme_poster

class plotnine_extra.theme_poster(base_size=20, base_family='')[source]

Bases: plotnine.theme_minimal

High-visibility theme for posters.

Large fonts, bold titles, generous spacing. Designed for readability at a distance.

Parameters:
  • base_size (float) – Base font size in points.

  • base_family (str) – Base font family.

clean_theme

class plotnine_extra.clean_theme[source]

Bases: plotnine.theme

Port of ggpubr::clean_theme.

Removes axis text, ticks, titles and grid lines while keeping the data ink. Used to declutter ridge plots and summary panels.

Styling Helpers

bgcolor

plotnine_extra.bgcolor(color='white')[source]

Set the panel and plot background colours.

Parameters:

color (str)

border

plotnine_extra.border(color='black', size=0.5, linetype='solid')[source]

Add a panel border.

Parameters:

grids

plotnine_extra.grids(axis='xy', color='#EBEBEB', size=0.4, linetype='solid')[source]

Add panel grid lines along the chosen axis.

Parameters:
  • axis (str, default "xy") – One of "x", "y" or "xy".

  • color (str)

  • size (float)

  • linetype (str)

rotate

plotnine_extra.rotate()[source]

Flip the coordinate system (alias of coord_flip).

rotate_x_text

plotnine_extra.rotate_x_text(angle=45, hjust=1, vjust=1)[source]

Rotate x-axis tick labels.

Parameters:

rotate_y_text

plotnine_extra.rotate_y_text(angle=45, hjust=1, vjust=1)[source]

Rotate y-axis tick labels.

Parameters:

rremove

plotnine_extra.rremove(name)[source]

Remove a named theme element.

Parameters:

name (str) – One of "x.text", "y.text", "xy.text", "axis.text", "x.title", "y.title", "xy.title", "axis.title", "x.ticks", "y.ticks", "ticks", "axis", "legend", "grid", "panel.grid".

xscale

plotnine_extra.xscale(type='none', **kwargs)[source]

Set the x-axis scale.

Parameters:

type (str) – One of "none", "log2", "log10", "sqrt".

yscale

plotnine_extra.yscale(type='none', **kwargs)[source]

Set the y-axis scale. See xscale() for the list of valid type values.

Parameters:

type (str)

font

plotnine_extra.font(which='title', size=None, color=None, face=None, family=None)[source]

Set the font of a named theme element.

Parameters:
  • which (str) – One of "title", "subtitle", "caption", "x", "y", "xy", "x.text", "y.text", "xy.text", "legend.title", "legend.text".

  • size (optional) – Passed straight through to element_text.

  • color (optional) – Passed straight through to element_text.

  • family (optional) – Passed straight through to element_text.

  • face (str, optional) – One of "plain", "bold", "italic", "bold.italic".

labs_pubr

plotnine_extra.labs_pubr(base_size=12, base_family='')[source]

A theme that bolds axis titles and increases their size.

Mirrors the publication-style typography in ggpubr::labs_pubr.

Parameters:

ggpar

plotnine_extra.ggpar(plot, title=None, subtitle=None, caption=None, xlab=None, ylab=None, legend=None, legend_title=None, palette=None, orientation=None, font_main=None, font_x=None, font_y=None, font_legend=None, x_text_angle=None, y_text_angle=None)[source]

One-shot setter for plot title / labels / legend / palette.

A subset of the kitchen-sink ggpubr ggpar interface. The most common arguments are supported; pass any further theme customisations as separate + theme(...) layers.

Parameters:
  • title (str | None)

  • subtitle (str | None)

  • caption (str | None)

  • xlab (str | None)

  • ylab (str | None)

  • legend (str | None)

  • legend_title (str | None)

  • palette (str | Sequence[str] | None)

  • orientation (str | None)

  • font_main (dict | None)

  • font_x (dict | None)

  • font_y (dict | None)

  • font_legend (dict | None)

  • x_text_angle (float | None)

  • y_text_angle (float | None)