Rust plotting library using Python (Matplotlib)
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-matplotlib
Add this to your Cargo.toml (choose the right version):
[dependencies]
plotpy = "*"
Examples
Contour
use plotpy::{Contour, Plot};
use russell_lab::generate3d;
use std::path::Path;
fn main() -> Result<(), &'static str> {
let n = 21;
let (x, y, z) = generate3d(-2.0, 2.0, -2.0, 2.0, n, n, |x, y| x * x - y * y);
let mut contour = Contour::new();
contour
.set_colorbar_label("temperature")
.set_colormap_name("terrain")
.set_selected_level(0.0, true);
contour.draw(&x, &y, &z);
let mut plot = Plot::new();
plot.add(&contour);
plot.set_labels("x", "y");
plot.save(Path::new("/tmp/plotpy/readme_contour.svg"))?;
Ok(())
}