Axes, layout, text and style
Subplots with a shared x-axis
A 2 × 2 grid of plots sharing the x limits.
Code of this example · cargo run --release -p plot-subplots-shared
Logarithmic scales
Log-log axes with minor ticks and a symmetric-log axis.
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.
#![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.
Code of this example · cargo run --release -p plot-formats
Annotations
Arrow, text, shaded band, rectangle and reference line.
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.
#![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.
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 withfig.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:
The same chart with the colour-blind safe Okabe–Ito palette:
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()).
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