plot::quick
On this page
- Re-exports
- Traits
Plottable1- Functions
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::linspacelinspace
Traits
PlottableSource
pub trait PlottableA figure or an Axes: what svg, png, save and show take.
let a = plot::line([0, 1], [0, 1]);
assert((try plot::svg(a)) == (try plot::svg(a.figure())));
The figure to render.
Functions
lineSource
pub fn line<X: Data, Y: Data>(x: X, y: Y) -> Axes A line plot.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
try plot::show(plot::bar(["a", "b"], [1, 2]));