An extensible plotting library for CLI applications.
Find the full documentation on doc.rs
To use termplot
, add the crate to your Cargo.toml
.
toml
[dependencies]
termplot = "0.1.0"
Here is a quick example of what plotting sin(x) / x
looks like.
```rust use termplot::*;
let mut plot = Plot::default(); plot.setdomain(Domain(-10.0..10.0)) .setcodomain(Domain(-0.3..1.2)) .settitle("Graph title") .setxlabel("X axis") .setylabel("Y axis") .setsize(Size::new(50, 25)) .add_plot(Box::new(plot::Graph::new(|x| x.sin() / x)));
println!("{plot}"); ``` Output of the previous example:
```rust use termplot::*; use rand::Rng;
let mut rng = rand::threadrng();
let values: Vec
let mut plot = Plot::default();
plot.setdomain(Domain(0.0..11.0)) .setcodomain(Domain(0.0..45.0)) .settitle("Graph title") .setxlabel("X axis") .setylabel("Y axis") .setsize(Size::new(50, 25)) .add_plot(Box::new(plot::Historigram::new( values, vec![0.0..2.0, 2.0..4.0, 4.0..6.0, 6.0..8.0, 8.0..10.0], )));
println!("{plot}"); ``` Output of the previous example:
It is also possible to compose multiple plots:
```rust use termplot::*; use rand::Rng;
let mut rng = rand::threadrng();
let values: Vec
let mut plot = Plot::default();
plot.setdomain(Domain(0.0..11.0)) .setcodomain(Domain(0.0..45.0)) .settitle("Graph title") .setxlabel("X axis") .setylabel("Y axis") .setsize(Size::new(50, 25)) .addplot(Box::new(plot::Historigram::new( values, vec![0.0..2.0, 2.0..4.0, 4.0..6.0, 6.0..8.0, 8.0..10.0], ))) .addplot(Box::new(plot::Graph::new(|x| { -2.0 * (x - 5.0).powf(2.0) + 40.0 })));
println!("{plot}"); ```
Output of the previous example:
MIT - Enjoy!