Skip to content

Instantly share code, notes, and snippets.

@fancellu
Created February 12, 2024 19:23
Show Gist options
  • Save fancellu/c8b4431cebc3dd5073b61cbb7ac1555a to your computer and use it in GitHub Desktop.
Save fancellu/c8b4431cebc3dd5073b61cbb7ac1555a to your computer and use it in GitHub Desktop.
Rust demo of rasciigraph, which plots simple ascii graphs, quite nice
use rand::Rng;
use rasciigraph::{plot, Config};
fn main() {
let vec = (0..70)
.map(|_| rand::thread_rng().gen::<f64>() * 13.0 - 3.0)
.collect::<Vec<_>>();
let plot = plot(
vec,
Config::default()
.with_offset(10)
.with_height(10)
.with_caption("Random values".to_string()),
);
println!("{}", plot)
}
@fancellu
Copy link
Author

Output example


      9.46    ┤╭╮        ╭╮
      8.22    ┼╯│        ││            ╭╮                  ╭╮  ╭╮
      6.98    ┤ │        ││        ╭─╮ │╰─╮    ╭╮  ╭╮      ││╭─╯│                ╭╮
      5.74    ┤ │        ││        │ │╭╯  │╭╮  ││  ││   ╭╮ │││  ╰╮               ││
      4.51    ┤ ╰╮       ││        │ ││   │││  ││  ││   ││ │││   │╭╮      ╭╮ ╭╮  ││
      3.27    ┤  │  ╭╮ ╭─╯│        │ ││   │││  ││  ││  ╭╯│ │││   │││      ││╭╯│  ││
      2.03    ┤  │  ││ │  │    ╭╮ ╭╯ ││   │││ ╭╯│ ╭╯│╭╮│ │╭╯╰╯   ╰╯│ ╭╮╭╮ │││ │  ││
      0.79    ┤  │  │╰─╯  │    ││ │  ││   ╰╯│ │ │ │ ││╰╯ ╰╯        │ ││││ │││ │  ││
     -0.44    ┤  ╰╮ │     │  ╭─╯│╭╯  ╰╯     │╭╯ │ │ ╰╯             ╰╮││││ │╰╯ │ ╭╯│
     -1.68    ┤   │ │     ╰╮ │  ││          ╰╯  ╰╮│                 ╰╯╰╯│╭╯   ╰╮│ │
     -2.92    ┤   ╰─╯      ╰─╯  ╰╯               ╰╯                     ╰╯     ╰╯ ╰─
                 Random values


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment