#plot #2d #3d #python #matplotlib

plotpy

Rust plotting library using Python (Matplotlib)

7 releases

Uses new Rust 2021

new 0.3.0 May 14, 2022
0.2.4 Oct 13, 2021
0.2.2 Sep 20, 2021
0.1.1 Aug 16, 2021

#79 in Math

Download history 1/week @ 2022-01-24 7/week @ 2022-01-31 4/week @ 2022-02-14 7/week @ 2022-02-21 1/week @ 2022-02-28 21/week @ 2022-03-14 18/week @ 2022-03-21 2/week @ 2022-03-28 7/week @ 2022-04-04 36/week @ 2022-04-25 55/week @ 2022-05-02 36/week @ 2022-05-09

127 downloads per month
Used in gemlab

MIT license

475KB
4K SLoC

Rust plotting library using Python (Matplotlib)

codecov

This package implements a plotting library, with its own functions. However, internally, this package generates a Python script with Matplotlib commands. Then, this package runs the script using process::Command.

For convenience, we use Vector and Matrix from Russell Lab.

Documentation:

Installation

Install some libraries:

sudo apt-get install liblapacke-dev libopenblas-dev python3-pip3
pip3 install matplotlib

Note We use pip3 because the version of Matplotlib needs to be at least 3.3.0 and "old" Ubuntu comes with 3.1.2.

Add this to your Cargo.toml:

[dependencies]
plotpy = "0.2"

Examples

Contour

use plotpy::{Contour, Plot, StrError};
use russell_lab::generate3d;

fn main() -> Result<(), StrError> {
    // generate (x,y,z) matrices
    let n = 21;
    let (x, y, z) = generate3d(-2.0, 2.0, -2.0, 2.0, n, n, |x, y| x * x - y * y);

    // configure contour
    let mut contour = Contour::new();
    contour
        .set_colorbar_label("temperature")
        .set_colormap_name("terrain")
        .set_selected_level(0.0, true);

    // draw contour
    contour.draw(&x, &y, &z);

    // add contour to plot
    let mut plot = Plot::new();
    plot.add(&contour);
    plot.set_labels("x", "y");

    // save figure
    plot.save("/tmp/plotpy/readme_contour.svg")?;
    Ok(())
}

readme_contour.svg

Superquadric

use plotpy::{Plot, StrError, Surface};

fn main() -> Result<(), StrError> {
    // star
    let r = &[1.0, 1.0, 1.0];
    let c = &[-1.0, -1.0, -1.0];
    let k = &[0.5, 0.5, 0.5];
    let mut star = Surface::new();
    star.set_colormap_name("jet")
        .draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;

    // pyramids
    let c = &[1.0, -1.0, -1.0];
    let k = &[1.0, 1.0, 1.0];
    let mut pyramids = Surface::new();
    pyramids
        .set_colormap_name("inferno")
        .draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;

    // rounded cube
    let c = &[-1.0, 1.0, 1.0];
    let k = &[4.0, 4.0, 4.0];
    let mut cube = Surface::new();
    cube.set_solid_color("#ee29f2")
        .draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;

    // sphere
    let c = &[0.0, 0.0, 0.0];
    let k = &[2.0, 2.0, 2.0];
    let mut sphere = Surface::new();
    sphere
        .set_colormap_name("rainbow")
        .draw_superquadric(c, r, k, -180.0, 180.0, -90.0, 90.0, 40, 20)?;

    // sphere (direct)
    let mut sphere_direct = Surface::new();
    sphere_direct.draw_sphere(&[1.0, 1.0, 1.0], 1.0, 40, 20)?;

    // add features to plot
    let mut plot = Plot::new();
    plot.add(&star)
        .add(&pyramids)
        .add(&cube)
        .add(&sphere)
        .add(&sphere_direct);

    // save figure
    plot.set_equal_axes(true)
        .set_figure_size_points(600.0, 600.0)
        .save("/tmp/plotpy/readme_superquadric.svg")?;
    Ok(())
}

readme_superquadric.svg

Dependencies

~18MB
~196K SLoC