Struct Mpl

Source
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::Show

Implementations§

Source§

impl Mpl

Source

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.

Source

pub fn new_3d<I>(opts: I) -> Self
where 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.

Source

pub fn new_3d_with<I, F>(opts: I, f: F) -> Self
where I: IntoIterator<Item = Opt>, F: FnOnce(Mpl) -> Mpl,

Like new_3d, but call a closure on the new Mpl between prelude and figure/axes initialization.

Source

pub fn new_grid<I>(nrows: usize, ncols: usize, opts: I) -> Self
where 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.

Source

pub fn new_grid_with<I, F>(nrows: usize, ncols: usize, opts: I, f: F) -> Self
where I: IntoIterator<Item = Opt>, F: FnOnce(Mpl) -> Mpl,

Like new_grid, but call a closure on the new Mpl between prelude and figure/axes initialization.

Source

pub fn new_gridspec<I, P>(gridspec_kw: I, positions: P) -> Self
where I: IntoIterator<Item = Opt>, P: IntoIterator<Item = GSPos>,

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.

Source

pub fn new_gridspec_with<I, P, F>(gridspec_kw: I, positions: P, f: F) -> Self
where I: IntoIterator<Item = Opt>, P: IntoIterator<Item = GSPos>, F: FnOnce(Mpl) -> Mpl,

Like new_gridspec, but call a closure on the new Mpl between prelude and figure/axes initialization.

Source

pub fn then<M: Matplotlib + 'static>(&mut self, item: M) -> &mut Self

Add a new command to self.

Source

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.

Source

pub fn code(&self, mode: Run) -> String

Build a Python script, but do not run it.

Source

pub fn run(&self, mode: Run) -> MplResult<()>

Build and run a Python script script in a Run mode.

Source

pub fn show(&self) -> MplResult<()>

Alias for self.run(Run::Show).

Source

pub fn save<P: AsRef<Path>>(&self, path: P) -> MplResult<()>

Alias for self.run(Run::Save(path)).

Source

pub fn saveshow<P: AsRef<Path>>(&self, path: P) -> MplResult<()>

Alias for self.run(Run::SaveShow(path))

Trait Implementations§

Source§

impl BitAnd<Run> for Mpl

Source§

type Output = Mpl

The resulting type after applying the & operator.
Source§

fn bitand(self, mode: Run) -> Self::Output

Performs the & operation. Read more
Source§

impl<T> BitAnd<T> for Mpl
where T: Matplotlib + 'static,

Source§

type Output = Mpl

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: T) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAnd for Mpl

Source§

type Output = Mpl

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Mpl) -> Self::Output

Performs the & operation. Read more
Source§

impl BitAndAssign<Run> for Mpl

Source§

fn bitand_assign(&mut self, mode: Run)

Performs the &= operation. Read more
Source§

impl<T> BitAndAssign<T> for Mpl
where T: Matplotlib + 'static,

Source§

fn bitand_assign(&mut self, rhs: T)

Performs the &= operation. Read more
Source§

impl BitAndAssign for Mpl

Source§

fn bitand_assign(&mut self, rhs: Mpl)

Performs the &= operation. Read more
Source§

impl BitOr<Run> for &Mpl

Source§

type Output = ()

The resulting type after applying the | operator.
Source§

fn bitor(self, mode: Run) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<Run> for Mpl

Source§

type Output = ()

The resulting type after applying the | operator.
Source§

fn bitor(self, mode: Run) -> Self::Output

Performs the | operation. Read more
Source§

impl Clone for Mpl

Source§

fn clone(&self) -> Mpl

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Mpl

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Mpl

Source§

fn default() -> Mpl

Returns the “default value” for a type. Read more
Source§

impl<T: Matplotlib + 'static> From<T> for Mpl

Source§

fn from(item: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Mpl

§

impl !RefUnwindSafe for Mpl

§

impl !Send for Mpl

§

impl !Sync for Mpl

§

impl Unpin for Mpl

§

impl !UnwindSafe for Mpl

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V