packages

plot::quick

On this page

One-call plots: each function starts an Axes with one layer, so it chains (plot::line(x, y).label("a").scatter(x, z)), adds (a + b overlays), lays out (a | b, a / b) and pipes (y |> plot::hist() |> plot::svg()). plot! is the shortest form.

Re-exports

core::num::linspaceSource

pub use core::num::linspace
  • linspace

Traits

PlottableSource

pub trait Plottable

A figure or an Axes: what svg, png, save and show take.

nabi
let a = plot::line([0, 1], [0, 1]);
assert((try plot::svg(a)) == (try plot::svg(a.figure())));

Functions

lineSource

pub fn line<X: Data, Y: Data>(x: X, y: Y) -> Axes

A line plot.

nabi
assert((try plot::line([0, 1], [1, 0]).svg()).contains("<path"));

scatterSource

pub fn scatter<X: Data, Y: Data>(x: X, y: Y) -> Axes

A scatter plot.

nabi
assert((try plot::scatter([1, 2], [2, 1]).svg()).contains("<circle"));

stepSource

pub fn step<X: Data, Y: Data>(x: X, y: Y, at: StepAt = StepAt::Post) -> Axes

A step plot.

nabi
assert((try plot::step([0, 1, 2], [0, 1, 0]).svg()).contains("<path"));

barSource

pub fn bar<H: Data>(labels: List<str>, heights: H) -> Axes

A bar chart over categories.

nabi
assert((try plot::bar(["x", "y"], [1, 2]).svg()).contains(">y<"));

histSource

pub fn hist<D: Data>(data: D, bins: Bins = Bins::Auto, density: bool = false) -> Axes

A histogram.

nabi
let svg = try [1.0, 2.0, 2.0, 3.0, 3.0, 3.0] |> plot::hist() |> plot::svg();
assert(svg.contains("<path"));

areaSource

pub fn area<X: Data, Y: Data>(x: X, y: Y) -> Axes

An area under a curve.

nabi
assert((try plot::area([0, 1], [1, 2]).svg()).contains("fill-opacity"));

fill_betweenSource

pub fn fill_between<X: Data, A: Data, B: Data>(x: X, y1: A, y2: B) -> Axes

The region between two curves.

nabi
assert((try plot::fill_between([0, 1], [0, 0], [1, 2]).svg()).contains("fill-opacity"));

errorbarSource

pub fn errorbar<X: Data, Y: Data, E: Data>(x: X, y: Y, yerr: E) -> Axes

Points with symmetric error bars.

nabi
assert((try plot::errorbar([0, 1], [1, 2], [0.1, 0.2]).svg()).contains("<circle"));

boxplotSource

pub fn boxplot(groups: List<List<f64>>, labels: List<str> = []) -> Axes

Box plots of groups.

nabi
assert((try plot::boxplot([[1.0, 2.0, 3.0]], ["a"]).svg()).contains(">a<"));

violinSource

pub fn violin(groups: List<List<f64>>, labels: List<str> = []) -> Axes

Violin plots of groups.

nabi
assert((try plot::violin([[1.0, 2.0, 3.0, 2.5]]).svg()).contains("<path"));

heatmapSource

pub fn heatmap<G: Grid>(z: G) -> Axes

A heatmap of a grid, row 0 at the bottom.

nabi
assert((try plot::heatmap([[1.0, 2.0], [3.0, 4.0]]).svg()).contains("<image"));

imshowSource

pub fn imshow<G: Grid>(z: G) -> Axes

An image of a grid, row 0 at the top, square pixels.

nabi
assert((try plot::imshow([[1.0, 2.0], [3.0, 4.0]]).svg()).contains("<image"));

contourSource

pub fn contour<G: Grid>(z: G, levels: List<f64> = []) -> Axes

Contour lines of a grid.

nabi
assert((try plot::contour([[0.0, 1.0], [1.0, 2.0]], [1.0]).svg()).contains("<path"));

contourfSource

pub fn contourf<G: Grid>(z: G, levels: List<f64> = []) -> Axes

Filled contours of a grid.

nabi
assert((try plot::contourf([[0.0, 1.0], [1.0, 2.0]]).svg()).contains("<path"));

quiverSource

pub fn quiver<X: Data, Y: Data, U: Data, V: Data>(x: X, y: Y, u: U, v: V) -> Axes

A vector field.

nabi
assert((try plot::quiver([0, 1], [0, 1], [1, 1], [0, 1]).svg()).contains("<path"));

svgSource

pub fn svg<P: Plottable>(p: P) throws (PlotError) -> str

The SVG of a figure or an Axes.

nabi
assert((try plot::svg(plot::line([0, 1], [0, 1]))).starts_with("<svg"));

pngSource

pub fn png<P: Plottable>(p: P, scale: f64 = 1.0) throws (PlotError) -> List<u8>

The PNG of a figure or an Axes.

nabi
assert((try plot::png(plot::line([0, 1], [0, 1])))[0] == 137);

saveSource

pub fn save<P: Plottable>(p: P, path: str) throws (PlotError)

Writes a figure or an Axes to an .svg or .png file.

nabi
use std::{env, fs, random};

let path = env::temp_dir() / f"plot_quick_{random::range(0u64..u64::MAX)}.svg";
try plot::save(plot::line([0, 1], [0, 1]), f"{path}");
try fs::remove_file(path);

showSource

pub fn show<P: Plottable>(p: P) throws (PlotError)

Prints a figure or an Axes to the terminal.

nabi
try plot::show(plot::bar(["a", "b"], [1, 2]));