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.
- Contour
Mut - A handle to contours created by
contour,contourforcontour3. - 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
plotand 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).
- 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. - Surface
Mut - A handle to a surface created by
surformesh. - Text
- A piece of text, stored as its source so that renderers typeset it lazily.
- 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 ascontourandsurf. - Interpreter
- How the source of a
Textis interpreted. - 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.
- 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().