packages

plot::figure

On this page

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 Figure

A figure: panels laid out in rows and columns, rendered as one image.

nabi
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<"));
  • pub fn of(ax: Axes) -> Figure§

    Source

    A one-panel figure of ax, with its size and theme if it set them.

    nabi
    assert(plot::Figure::of(plot::axes().size_px(100.0, 80.0)).panels().len() == 1);
    
  • pub fn grid(panels: List<Axes>, cols: usize) -> Figure§

    Source

    Panels in a grid of cols columns, filled row by row.

    nabi
    let 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);
    
  • pub fn size(self, w: f64, h: f64) -> Figure§

    Source

    The size in px (CSS pixels; PNG output multiplies by its scale).

    nabi
    assert((try plot::line([0, 1], [0, 1]).figure().size(200.0, 100.0).svg()).contains("height=\"100\""));
    
  • pub fn title(self, s: str) -> Figure§

    Source

    A title above all panels.

    nabi
    assert((try plot::line([0, 1], [0, 1]).figure().title("All").svg()).contains(">All<"));
    
  • pub fn theme(self, t: Theme) -> Figure§

    Source

    The theme for every panel.

    nabi
    assert((try plot::line([0, 1], [0, 1]).figure().theme(plot::Theme::dark()).svg()).contains("#141114"));
    
  • pub fn panels(self) -> List<Axes>§

    Source

    The panels in layout order.

    nabi
    let a = plot::line([0, 1], [0, 1]);
    assert((a | a | a).panels().len() == 3);
    
  • pub fn scene(self) throws (PlotError) -> pkg::scene::Scene§

    Source

    The drawing primitives for a canvas of the figure's size.

    nabi
    let s = try plot::line([0, 1], [0, 1]).figure().scene();
    assert(s.width == 640.0 && s.items.len() > 3);
    
  • pub fn svg(self) throws (PlotError) -> str§

    Source

    The SVG document: exact text, deterministic bytes.

    nabi
    assert((try plot::line([0, 1], [0, 1]).figure().svg()).starts_with("<svg"));
    
  • pub fn png(self, scale: f64 = 1.0) throws (PlotError) -> List<u8>§

    Source

    A PNG image, scale device pixels per px (2 for HiDPI).

    nabi
    let 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"
    
  • pub fn term(self, cols: usize = 80, rows: usize = 24, color: bool = false) throws (PlotError) -> str§

    Source

    The figure drawn with Unicode braille and block characters in cols x rows cells; color adds 24-bit ANSI colours.

    nabi
    let t = try plot::line([0, 1, 2], [0, 1, 0]).term(cols: 40, rows: 12);
    assert(t.lines().count() == 12);
    
  • pub fn save(self, path: str) throws (PlotError)§

    Source

    Writes the figure to path: SVG for .svg, PNG for .png.

    nabi
    use 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);
    
  • pub fn show(self) throws (PlotError)§

    Source

    Prints the terminal rendering, 80 x 24.

    nabi
    try plot::line([0, 1], [0, 1]).figure().show();
    
  • pub fn figure(self) -> Figure§

    Source

    This figure (so a figure and an Axes take the same calls).

    nabi
    let f = plot::line([0, 1], [0, 1]).figure();
    assert(f.figure().panels().len() == 1);
    
Trait implementations 5
  • impl RichDisplay for Figure
  • impl ops::BitOr<Axes> for Figure
  • impl ops::BitOr<Figure> for Figure
  • impl ops::Div<Axes> for Figure
  • impl ops::Div<Figure> for Figure

Enums

NodeSource

pub enum Node

A node of the layout tree.

nabi
let f = plot::line([0, 1], [0, 1]) / plot::line([0, 1], [1, 0]);
assert(f.panels().len() == 2);