#plotting #plot #visualization #latex #pgfplots

pgfplots

A Rust library to generate publication-quality figures

5 releases (3 breaking)

Uses new Rust 2021

0.4.0 Jun 20, 2022
0.3.1 Jun 5, 2022
0.3.0 Jun 5, 2022
0.2.0 May 26, 2022
0.1.0 May 24, 2022

#31 in Visualization

Download history 49/week @ 2022-05-22 23/week @ 2022-05-29 64/week @ 2022-06-05 16/week @ 2022-06-12 39/week @ 2022-06-19

145 downloads per month

MIT license

66KB
1K SLoC

PGFPlots

Test Status Crates.io GitHub commits since latest release (by date)

A Rust library to generate publication-quality figures. This crate is a PGFPlots code generator, and provides utilities to create, customize, and compile high-quality plots.

Usage

Add the following to your Cargo.toml file:

[dependencies]
pgfplots = { version = "0.4", features = ["inclusive"] }

Plotting a quadratic function is as simple as:

use pgfplots::axis::plot::Plot2D;

let mut plot = Plot2D::new();
plot.coordinates = (-100..100)
    .into_iter()
    .map(|i| (f64::from(i), f64::from(i*i)).into())
    .collect();

plot.show()?;

Examples

A more extensive list of examples and their source code is available in the examples/ directory (runnable with cargo run --all-features --example example_name).

[code] [code] [code]

Features

  • Inclusive: Allow users to process the LaTeX code that generates figures without relying on any externally installed software, configuration, or resource files. This is achieved by including the tectonic crate as a dependency.

    If you already have a LaTeX distribution installed in your system, it is recommended not to use this feature and process the LaTeX code directly; this will significantly reduce compilation and processing times. Plotting a quadratic function is still very simple:

     use pgfplots::axis::plot::Plot2D;
     use std::process::{Command, Stdio};
    
     let mut plot = Plot2D::new();
     plot.coordinates = (-100..100)
     	.into_iter()
     	.map(|i| (f64::from(i), f64::from(i*i)).into())
     	.collect();
    
     let argument = plot.standalone_string().replace('\n', "").replace('\t', "");
     Command::new("pdflatex")
     	.stdout(Stdio::null())
     	.stderr(Stdio::null())
     	.arg("-interaction=batchmode")
     	.arg("-halt-on-error")
     	.arg("-jobname=figure")
     	.arg(argument)
     	.status();
    

Want to contribute?

There are multiple ways to contribute:

  • Install and test PGFPlots. If it doesn't work as expected please open an issue.
  • Comment/propose a fix on some of the current open issues.
  • Read through the documentation. If there is something confusing, or you have a suggestion for something that could be improved, please let the maintainer(s) know.
  • Help evaluate open pull requests, by testing locally and reviewing what is proposed.

Dependencies

~0–4.5MB
~95K SLoC