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.
- Byte
Matrix - A dense two-dimensional array of bytes stored in row-major order: the counterpart of
Matrixfor 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.
- Contour
Mut - A handle to contours created by
contour,contourforcontour3. - Export
Report - What an export left off the page, returned by
Figure::export_pdfandFigure::export_pdf_with. - Figure
- A figure: a page of a fixed physical size holding axes arranged in a grid of tiles.
- Image
Mut - A handle to a true-colour image created by
image. - Indexed
Image Mut - A handle to a colour-indexed image created by
indexed_image. - LineMut
- A handle to a line created by
plotand its relatives. - Mapped
Image Mut - 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.
- Quiver
Mut - A handle to arrows created by
quiverorquiver3. - Raster
Options - 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. - Scatter
Mut - A handle to a scatter created by
scatterorscatter3. - Scene
Warning - 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. - Surface
Mut - A handle to a surface created by
surf,meshorsurface. - Text
- A piece of text, stored as its source so that renderers typeset it lazily.
- Validation
Issue - A single problem found by validation.
- Validation
Report - The outcome of validating a figure.
Enums§
- Color
Spec - 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.
- Grid
Coords - The coordinates of a grid along one dimension, passed as the
xoryargument of gridded plots such ascontour,surfandsurface. - Image
Plane - 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.
- Image
Values - 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
Textis interpreted. - Issue
Kind - The category of a validation problem.
- Legend
Location - The placement of a legend inside the plot area.
- Marker
- The shape of the markers drawn at data points. The shape of a marker.
- OutOf
Range - 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.
- Raster
Policy - 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§
- Into
Color Spec - A value that can be passed wherever a colour is set.
Functions§
- linspace
- Returns
nevenly spaced values fromstarttoendinclusive. - logspace
- Returns
nlogarithmically spaced values from10^start_expto10^end_expinclusive. - meshgrid
- Returns the coordinates of every point of the rectilinear grid defined by the
vectors
xandy, as two matrices of shapey.len()byx.len().