Skip to main content

Crate ironlab

Crate ironlab 

Source
Expand description

MATLAB-flavoured Rust API for building, viewing and exporting scientific figures.

A Figure is built by placing axes in a grid of tiles and adding plots to them with functions named after their MATLAB equivalents: plot, scatter, contour, quiver, surf and their relatives. Each plotting function returns a handle whose chained setters change the properties of the new plot, in the way that MATLAB name–value arguments do. The figure can then be shown in the interactive viewer, saved as a .fig file (or as JSON) or exported to PDF.

Every call writes directly to the retained figure IR of the ir crate, which is the single source of truth for what is drawn. Builder calls never panic because of inconsistent input (such as arrays of different lengths or a tile outside the layout); such problems are reported by Figure::validate, and are checked again before the figure is exported or shown.

§Example

use ironlab::prelude::*;

let x = linspace(0.0, 2.0 * std::f64::consts::PI, 200);
let sin: Vec<f64> = x.iter().map(|x| x.sin()).collect();
let cos: Vec<f64> = x.iter().map(|x| x.cos()).collect();

let mut fig = Figure::new().size_mm(120.0, 80.0).title("Trigonometric functions");
let mut ax = fig.axes(0, 0);
ax.plot(&x, &sin).display_name("$\\sin x$");
ax.plot(&x, &cos).display_name("$\\cos x$").dash(Dash::Dashed);
ax.xlabel("$x$").ylabel("$f(x)$").legend(LegendLocation::NorthEast);

assert!(fig.validate().is_valid());

Showing and exporting a figure:

use ironlab::prelude::*;

let x = linspace(-1.5, 1.5, 61);
let y = linspace(-1.5, 1.5, 61);
let z = Matrix::from_fn(y.len(), x.len(), |row, col| x[col].powi(2) - y[row].powi(2));

let mut fig = Figure::new().title("A saddle");
fig.axes(0, 0).surf(&x, &y, &z);
fig.export_pdf("saddle.pdf")?;
fig.show()?;

Re-exports§

pub use ironlab_ir as ir;

Modules§

prelude
The types and functions needed to build figures, for glob import.

Structs§

AxesMut
A handle to one axes of a figure, through which plots are added and axes properties are set.
Color
An sRGB colour with straight (non-premultiplied) alpha.
ContourMut
A handle to contours created by contour, contourf or contour3.
Figure
A figure: a page of a fixed physical size holding axes arranged in a grid of tiles.
LineMut
A handle to a line created by plot and its relatives.
Matrix
A dense two-dimensional array of values stored in row-major order.
NodeId
A stable identifier of a node (the figure, an axes or an artist).
QuiverMut
A handle to arrows created by quiver or quiver3.
RasterOptions
How a dense artist is drawn when the figure is exported, and at what resolution it is rasterised. See Figure::export_pdf_with. The settings controlling the raster fallback for dense content.
ScatterMut
A handle to a scatter created by scatter or scatter3.
SurfaceMut
A handle to a surface created by surf or mesh.
Text
A piece of text, stored as its source so that renderers typeset it lazily.
ValidationReport
The outcome of validating a figure.

Enums§

ColorSpec
How a colour is chosen for a stroke, fill or marker.
Colormap
The name of a colormap. The name of a colormap.
Dash
The dash pattern of a line. The dash pattern of a stroked line.
Dim
The coordinate dimension of an axes, used to link axes and set limits. A coordinate dimension of an axes.
Error
An error returned when a figure cannot be saved, loaded, linked, exported or shown.
GridCoords
The coordinates of a grid along one dimension, passed as the x or y argument of gridded plots such as contour and surf.
Interpreter
How the source of a Text is interpreted.
LegendLocation
The placement of a legend inside the plot area.
Marker
The shape of the markers drawn at data points. The shape of a marker.
Parameter
A named value that describes a figure, such as the Reynolds number of the flow that it shows or the name of the solver that produced its data.
RasterPolicy
How a dense artist is drawn when the figure is exported, and at what resolution it is rasterised. See Figure::export_pdf_with. How the exporter chooses between vector and raster output for content the scene compiler marked as dense.
Scale
The mapping from data values to positions along an axis.

Traits§

IntoColorSpec
A value that can be passed wherever a colour is set.

Functions§

linspace
Returns n evenly spaced values from start to end inclusive.
logspace
Returns n logarithmically spaced values from 10^start_exp to 10^end_exp inclusive.
meshgrid
Returns the coordinates of every point of the rectilinear grid defined by the vectors x and y, as two matrices of shape y.len() by x.len().