Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Axes, layout, text and style

Subplots with a shared x-axis

A 2 × 2 grid of plots sharing the x limits.

Subplots with a shared x-axis

Code of this example · cargo run --release -p plot-subplots-shared


Logarithmic scales

Log-log axes with minor ticks and a symmetric-log axis.

Logarithmic scales

Code of this example · cargo run --release -p plot-log-scales


Broken axes

Axis::break_at(from, to) leaves an empty range out of an axis: one very large bar next to small ones stays readable, and a recording with a long outage does not waste the plot on the gap. The break is marked with a gap and // on the axis, ticks are placed per segment and lines do not jump over it.

Broken axes
#![allow(unused)]
fn main() {
ax.y_axis().break_at(25.0, 920.0);
}

Code of this example · cargo run --release -p plot-broken-axis


Tick formats

SI-prefixed and percent tick labels.

Tick formats

Code of this example · cargo run --release -p plot-formats


Annotations

Arrow, text, shaded band, rectangle and reference line.

Annotations

Code of this example · cargo run --release -p plot-annotations


Math notation

$...$ in any text (titles, axis labels, legends, annotations) is typeset from a TeX subset: superscripts and subscripts, fractions, roots, accents, Greek letters, big operators, function names, \mathrm, \mathbb, … It is laid out into ordinary text and lines, so PNG, SVG, PDF and the GPU backend all show the same result.

Math notation
#![allow(unused)]
fn main() {
ax.y_label(r"$\sigma^2$ [$\mathrm{m^2\,s^{-2}}$]");
ax.text(0.5, 0.5, r"$\int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}$");
}

Code of this example · cargo run --release -p plot-math


Text in any language

Labels in Chinese, Japanese, Korean, Arabic, Hebrew, Hindi, Thai, Greek, Turkish and Ukrainian, plus color emoji. Characters the theme font lacks come from system fonts (scanned once, the first time they are needed), Arabic and Hebrew are laid out right to left and shaped, and emoji are drawn from a color emoji font. Latin text keeps a fast path.

Text in any language

The fonts come from the system: on Linux, for example, fonts-noto-cjk, fonts-noto-core and fonts-noto-color-emoji. In SVG output the text is written as text, so the viewer picks its own fonts.

Code of this example · cargo run --release -p plot-international


Accessibility

Charts for everyone:

  • SVG, PDF and HTML output carry an accessible name and a description that screen readers read: fig.alt_text() generates it from the plots, axes, ranges and series, or set your own with fig.description(..).
  • fig.color_warnings() lists series whose colors are hard to tell apart, normally or with protanopia, deuteranopia or tritanopia.
  • Pixels::simulate(Cvd::Deuteranopia) shows a chart as people with a color vision deficiency see it.

Red, green and orange lines — normal, deuteranopia, protanopia, tritanopia:

Risky colors as seen with color vision deficiencies

The same chart with the colour-blind safe Okabe–Ito palette:

Okabe-Ito colors as seen with color vision deficiencies

Output:

Alt text: Red / green / orange. Line chart; quarter from 0.850 to 4.150; sales [k€] from 10.55 to 23.77. Series: north (11.148 to 14.988); south (12.097 to 19.997); east (11.94 to 23.17).

warning: "north" and "south" look alike with deuteranopia
warning: "south" and "east" look alike with protanopia

with Okabe–Ito: 0 warnings

Code of this example · cargo run --release -p plot-accessibility


Themes

The same chart in every built-in theme (Theme::presets()).

Themes Themes Themes Themes Themes Themes Themes Themes

Theme::high_contrast() is for low vision and projectors: black on white, heavier lines, larger text and dark colors each at least 4.5:1 against white.

Code of this example · cargo run --release -p plot-themes