pub struct Mpl { /* private fields */ }Expand description
Main script builder type.
Plotting scripts are built by combining base Mpls with either individual
commands represented by types implementing Matplotlib (via
then) or other Mpls (via concat). Both
operations are overloaded onto the & operator.
When a script is ready to be run, Mpl::run appends the appropriate IO
commands to the end of the file before writing to the OS’s default temp
directory (e.g. /tmp on Linux) and calling the system’s default python3
executable. Files in the temp directory are cleaned up afterwards. Mpl can
also interact with the Run objects through both the & and |
operators, where instead of producing a Result like run, a panic is
raised on an error. & produces a final Mpl to be used in later
operations, while | returns ().
use std::f64::consts::TAU;
use mpl::{ Mpl, Run, MatplotlibOpts, commands as c };
let dx: f64 = TAU / 1000.0;
let x: Vec<f64> = (0..1000_u32).map(|k| f64::from(k) * dx).collect();
let y1: Vec<f64> = x.iter().copied().map(f64::sin).collect();
let y2: Vec<f64> = x.iter().copied().map(f64::cos).collect();
Mpl::default()
& c::plot(x.clone(), y1).o("marker", "o").o("color", "b")
& c::plot(x, y2).o("marker", "D").o("color", "r")
| Run::ShowImplementations§
Source§impl Mpl
impl Mpl
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty plotting script.
The resulting plot will implicitly pull in
DefPrelude and
DefInit when run (or a
synonym) is called if no other objects with Matplotlib::is_prelude == true are added.
Sourcepub fn new_3d<I>(opts: I) -> Selfwhere
I: IntoIterator<Item = Opt>,
pub fn new_3d<I>(opts: I) -> Selfwhere
I: IntoIterator<Item = Opt>,
Create a new plotting script, initializing to a figure with a single set
of 3D axes (of type mpl_toolkits.mplot3d.axes3d.Axes3D).
This pulls in DefPrelude, but not
DefInit.
Options are passed to the construction of the Axes3D object.
Sourcepub fn new_3d_with<I, F>(opts: I, f: F) -> Self
pub fn new_3d_with<I, F>(opts: I, f: F) -> Self
Like new_3d, but call a closure on the new Mpl
between prelude and figure/axes initialization.
Sourcepub fn new_grid<I>(nrows: usize, ncols: usize, opts: I) -> Selfwhere
I: IntoIterator<Item = Opt>,
pub fn new_grid<I>(nrows: usize, ncols: usize, opts: I) -> Selfwhere
I: IntoIterator<Item = Opt>,
Create a new plotting script, initializing to a figure with a regular
grid of plots. All Axes objects will be stored in a 2D Numpy array
under the local variable AX, and the script will be initially focused
on the upper-left corner of the array, i.e. ax = AX[0, 0].
This pulls in DefPrelude, but not
DefInit.
Options are passed to the call to pyplot.subplots.
Sourcepub fn new_grid_with<I, F>(nrows: usize, ncols: usize, opts: I, f: F) -> Self
pub fn new_grid_with<I, F>(nrows: usize, ncols: usize, opts: I, f: F) -> Self
Like new_grid, but call a closure on the new Mpl
between prelude and figure/axes initialization.
Sourcepub fn new_gridspec<I, P>(gridspec_kw: I, positions: P) -> Self
pub fn new_gridspec<I, P>(gridspec_kw: I, positions: P) -> Self
Create a new plotting script, initializing a figure with Matplotlib’s
gridspec. Keyword arguments are passed to
pyplot.Figure.add_gridspec, and each subplot’s position in the
gridspec is specified using a GSPos. All Axes objects will be
stored in a 1D Numpy array under the local variable AX, and the script
will be initially focused to the subplot corresponding to the first
GSPos encountered, i.e. ax = AX[0].
This pulls in DefPrelude, but not
DefInit.
Sourcepub fn new_gridspec_with<I, P, F>(gridspec_kw: I, positions: P, f: F) -> Self
pub fn new_gridspec_with<I, P, F>(gridspec_kw: I, positions: P, f: F) -> Self
Like new_gridspec, but call a closure on the new
Mpl between prelude and figure/axes initialization.
Sourcepub fn then<M: Matplotlib + 'static>(&mut self, item: M) -> &mut Self
pub fn then<M: Matplotlib + 'static>(&mut self, item: M) -> &mut Self
Add a new command to self.
Sourcepub fn concat(&mut self, other: &Self) -> &mut Self
pub fn concat(&mut self, other: &Self) -> &mut Self
Combine self with other, moving all commands marked with
is_prelude == true to the top (with those
from self before those from other) but maintaining command order
otherwise.
Sourcepub fn run(&self, mode: Run) -> MplResult<()>
pub fn run(&self, mode: Run) -> MplResult<()>
Build and run a Python script script in a Run mode.
Trait Implementations§
Source§impl<T> BitAnd<T> for Mplwhere
T: Matplotlib + 'static,
impl<T> BitAnd<T> for Mplwhere
T: Matplotlib + 'static,
Source§impl BitAndAssign<Run> for Mpl
impl BitAndAssign<Run> for Mpl
Source§fn bitand_assign(&mut self, mode: Run)
fn bitand_assign(&mut self, mode: Run)
&= operation. Read moreSource§impl<T> BitAndAssign<T> for Mplwhere
T: Matplotlib + 'static,
impl<T> BitAndAssign<T> for Mplwhere
T: Matplotlib + 'static,
Source§fn bitand_assign(&mut self, rhs: T)
fn bitand_assign(&mut self, rhs: T)
&= operation. Read moreSource§impl BitAndAssign for Mpl
impl BitAndAssign for Mpl
Source§fn bitand_assign(&mut self, rhs: Mpl)
fn bitand_assign(&mut self, rhs: Mpl)
&= operation. Read more