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, image and their relatives (MATLAB’s imagesc is mapped_image, and MATLAB’s pcolor is surface in a two-dimensional axes). 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.
ByteMatrix
A dense two-dimensional array of bytes stored in row-major order: the counterpart of Matrix for 8-bit data, such as the classes of a colour-indexed image or the samples of a greyscale image.
Color
An sRGB colour with straight (non-premultiplied) alpha.
ContourMut
A handle to contours created by contour, contourf or contour3.
ExportReport
What an export left off the page, returned by Figure::export_pdf and Figure::export_pdf_with.
Figure
A figure: a page of a fixed physical size holding axes arranged in a grid of tiles.
ImageMut
A handle to a true-colour image created by image.
IndexedImageMut
A handle to a colour-indexed image created by indexed_image.
LineMut
A handle to a line created by plot and its relatives.
MappedImageMut
A handle to a colour-mapped image created by mapped_image.
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).
Pixels
The pixels of a true-colour image: 8-bit components stored together, pixel by pixel, in row-major order.
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.
SceneWarning
A problem the scene compiler found while drawing a figure that did not prevent the figure from being drawn, naming the node it concerns. See ExportReport. A problem found while compiling a figure that did not prevent the figure from being drawn.
SurfaceMut
A handle to a surface created by surf, mesh or surface.
Text
A piece of text, stored as its source so that renderers typeset it lazily.
ValidationIssue
A single problem found by validation.
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, surf and surface.
ImagePlane
The plane of an axes in which an image lies, with its offset along the third axis. The plane of an axes in which an image lies, with the offset of the plane along the third axis.
ImageValues
The values of a colour-indexed or colour-mapped image: a matrix of floating-point values or a matrix of bytes.
Interpreter
How the source of a Text is interpreted.
IssueKind
The category of a validation problem.
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.
OutOfRange
What a colour-indexed or colour-mapped image draws for a pixel it cannot colour. What is drawn for a pixel of a colour-indexed or colour-mapped image that the artist cannot colour: an index outside the colormap, a value outside the colour limits, or an index or value that is not finite.
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().