plot::figure
Figures: a layout tree of Axes (rows and columns, nested), a size, a
theme and a title, rendered to SVG, PNG or the terminal. | puts
panels side by side and / stacks them, as R's patchwork does.
Structs
FigureSource
pub struct FigureA figure: panels laid out in rows and columns, rendered as one image.
let pair = plot::line([0, 1, 2], [0, 1, 4]) | plot::scatter([0, 1, 2], [4, 1, 0]);
let fig = pair.title("Two panels").size(800.0, 300.0);
let svg = try fig.svg();
assert(svg.contains("width=\"800\"") && svg.contains(">Two panels<"));
A one-panel figure of
ax, with its size and theme if it set them.nabiassert(plot::Figure::of(plot::axes().size_px(100.0, 80.0)).panels().len() == 1);Panels in a grid of
colscolumns, filled row by row.nabilet panels = [plot::line([0, 1], [0, 1]), plot::line([0, 1], [1, 0]), plot::hist([1.0, 2.0, 2.0])]; let fig = plot::Figure::grid(panels, 2); assert((try fig.svg()).count("clipPath id") == 3);The size in px (CSS pixels; PNG output multiplies by its scale).
nabiassert((try plot::line([0, 1], [0, 1]).figure().size(200.0, 100.0).svg()).contains("height=\"100\""));A title above all panels.
nabiassert((try plot::line([0, 1], [0, 1]).figure().title("All").svg()).contains(">All<"));The theme for every panel.
nabiassert((try plot::line([0, 1], [0, 1]).figure().theme(plot::Theme::dark()).svg()).contains("#141114"));The panels in layout order.
nabilet a = plot::line([0, 1], [0, 1]); assert((a | a | a).panels().len() == 3);The drawing primitives for a canvas of the figure's size.
nabilet s = try plot::line([0, 1], [0, 1]).figure().scene(); assert(s.width == 640.0 && s.items.len() > 3);The SVG document: exact text, deterministic bytes.
nabiassert((try plot::line([0, 1], [0, 1]).figure().svg()).starts_with("<svg"));A PNG image,
scaledevice pixels per px (2 for HiDPI).nabilet bytes = try plot::line([0, 1], [0, 1]).size_px(64.0, 48.0).png(scale: 2.0); assert(bytes[1] == 80 && bytes.len() > 100); // "PNG"
Sourcepub fn term(§self, cols: usize = 80, rows: usize = 24, color: bool = false) throws (PlotError) -> str The figure drawn with Unicode braille and block characters in
colsxrowscells;coloradds 24-bit ANSI colours.nabilet t = try plot::line([0, 1, 2], [0, 1, 0]).term(cols: 40, rows: 12); assert(t.lines().count() == 12);Writes the figure to
path: SVG for.svg, PNG for.png.nabiuse std::{env, fs, random}; let path = env::temp_dir() / f"plot_fig_{random::range(0u64..u64::MAX)}.png"; try plot::line([0, 1], [0, 1]).figure().size(60.0, 40.0).save(f"{path}"); assert((try fs::read(path))[1] == 80); try fs::remove_file(path);Prints the terminal rendering, 80 x 24.
nabitry plot::line([0, 1], [0, 1]).figure().show();This figure (so a figure and an Axes take the same calls).
nabilet f = plot::line([0, 1], [0, 1]).figure(); assert(f.figure().panels().len() == 1);
Enums
NodeSource
pub enum NodeA node of the layout tree.
let f = plot::line([0, 1], [0, 1]) / plot::line([0, 1], [1, 0]);
assert(f.panels().len() == 2);
An empty cell.