Rust crate that provides a convenient macro to quickly plot variables.

Overview

Debug Plotter

This crate provides a convenient macro to quickly plot variables.

Documentation

For more information on how to use this crate, please take a look at the documentation or the examples.

Usage

An Example

In this example, we quickly want to plot the variables a, b, and c. Optionally, we can name the plot. Plots are saved as a PNG image in the plots directory that is created in the working directory.

fn main() {
    for a in 0usize..10usize {
        let b = (a as f32 / 2.0).sin() * 10.0;
        let c = 5 - (a as i32);

        debug_plotter::plot!(a, b, c where caption = "My Plot");
    }
}

The example above generates a plot named "My Plot" and saves it to 'plots/My_Plot.png`.

Basic PLot

Additional Use Cases

The macro takes a list of variables. By default, the value of the variable is mapped to the y axis, and the x axis shows the iteration number.

debug_plotter::plot!(a, b, c);

It is possible to pass a tuple if you want the x axis to be another value instead of the iteration number.

debug_plotter::plot!((x, a), (x, b), (x, c));

It is also possible to rename variables in the legend using the keyword as.

debug_plotter::plot!(a as "Alice", b as "Bob", c as "Charlie");

It is possible to provide additional options for the plot after a where keyword.

debug_plotter::plot!(a, b, c where caption = "My Caption");

The following table lists all available options.

Identifier Example Value Description
caption "caption" Sets the caption of the plot.
size (400, 300) Sets the size of the resulting image or window.
x_desc "x description" Sets the description of the x axis.
y_desc "y description" Sets the description of the y axis.
path "/plots/my_plot.jpg" Defines where the plot is saved.
x_range 0f64..100f64 Defines start and end of the x axis.
y_range 0f64..100f64 Defines start and end of the y axis.
values 1000usize Defines the maximal number of values that are stored. If the macro is called more times than this number, the oldest value is dropped.
live true Enables live mode which opens the plot in a window with live updates.

Features Overview

The following table lists all available features.

Feature Description
debug Enabled by default, disable to avoid compiling the dependencies in release mode.
plot-release Disabled by default, enable to start plotting in release mode.
live Enabled by default, enables live debugging by opening a window when passing live = true to the plot! macro.

Debug and Release Mode

Variables are only plotted if your code is run in debug mode. In release mode, plot! macros are ignored. If you want to avoid compiling the dependencies for this crate in release mode, add --no-default-features. If you want to plot variables in release mode, use the feature plot-release.

You might also like...
Macro for Python-esque comprehensions in Rust

Cute Macro for Python-esque list comprehensions in Rust. The c! macro implements list and hashmap comprehensions similar to those found in Python, all

A Rust macro for writing regex pattern matching.

regexm A Rust macro for writing regex pattern matching.

Rust macro to make recursive function run on the heap (i.e. no stack overflow).

Decurse Example #[decurse::decurse] // 👈 Slap this on your recursive function and stop worrying about stack overflow! fn factorial(x: u32) - u32 {

Rust macro that uses GPT3 codex to generate code at compiletime

gpt3_macro Rust macro that uses GPT3 codex to generate code at compiletime. Just describe what you want the function to do and (optionally) define a f

No-nonsense input!(...) macro for Rust

No-nonsense input!(...) macro for Rust

hado-rshado — A little macro for writing haskell-like do expressions without too much ceremony

hado Monadic haskell-like expressions brought to rust via the hado! macro What? A little macro for writing haskell-like do expressions without too muc

Yet another geter/setter derive macro.

Gusket Gusket is a getter/setter derive macro. Comparison with getset: gusket only exposes one derive macro. No need to derive(Getters, MutGetters, Se

A proc-macro to get Vecu8 from struct and vise versa

byteme A proc-macro to convert a struct into Vec and back by implemeting From trait on the struct. The conversion is Big Endian by default. We have ma

Derive macro for encoding/decoding instructions and operands as bytecode

bytecoding Derive macro for encoding and decoding instructions and operands as bytecode. Documentation License Licensed under either of Apache License

Comments
  • No output when using plot macro in tests.

    No output when using plot macro in tests.

    I've been trying to use debug_plotter::plot!() in one of my tests, but I don't get any output. Am I doing something wrong ? It compiles and runs fine otherwise ...

    Best, N

    opened by the-drunk-coder 5
  • Macro is unusable without declaring your own feature flags

    Macro is unusable without declaring your own feature flags

    Currently,

    #[cfg(any(debug_assertions,feature = "plot-release"))]
    #[cfg(feature = "debug")]
    

    is emitted from the macro, meaning that the crate that uses it has to define/activate these features rather than debug-plotter itself.

    I think this might also relate to #2, as I've seen the same "unused variable" message in rust-analyzer until I added plot-release and debug as feature flags to my crate instead.

    opened by seritools 3
  • Unable to follow basic example

    Unable to follow basic example

    Using vscode with rust_analyzer, the macro doesn't appear to be recognizing the variables passed in.

    There also appear to be typos in the docs, (missing ! to designate the macro calls)

    image

    There is no output, and no runtime errors when executed with cargo run

    opened by zshift 3
  • Add missing conditional compiler macros

    Add missing conditional compiler macros

    Since the piston dependency is now out of date I had to disable it via default_features = false for now in my Cargo.toml but ran into some errors due to conditionally compiling without it. Here are the missing macros. Note that someone should update the piston backend code so that the live feature works again.

    opened by toastmod 1
Owner
Fabian Bösiger
Fabian Bösiger
A convenient tracing config and init lib, with symlinking and local timezone.

clia-tracing-config A convenient tracing config and init lib, with symlinking and local timezone. Use these formats default, and can be configured: pr

Cris Liao 5 Jan 3, 2023
Rust Lambda Extension for any Runtime to preload SSM Parameters as 🔐 Secure Environment Variables!

?? Crypteia Rust Lambda Extension for any Runtime to preload SSM Parameters as Secure Environment Variables! Super fast and only performaned once duri

Custom Ink 34 Jan 7, 2023
Fast, initializable, and thread safe static variables

tagged_cell Fast, initializable, and thread safe static variables Overview Borrows the excellent ZST based tagging implementation (linked below) to gu

David Schwarz 8 Nov 10, 2022
Rust crate which provides direct access to files within a Debian archive

debarchive This Rust crate provides direct access to files within a Debian archive. This crate is used by our debrep utility to generate the Packages

Pop!_OS 11 Dec 18, 2021
A Rust crate that provides a simple interface for LZMA compression and decompression.

rust-lzma Documentation This crate provides a simple interface to liblzma. LZMA is more commonly known as XZ or 7zip, (as in, files with the .xz or .7

null 52 Nov 26, 2022
Quickly mint NFT(able)s port forwards remotely

Easy expose A really simple way to expose some service behind a NAT, similar to rathole and frp. WARNING: This does not secure the channel, or even do

Ben Simms 3 Dec 3, 2022
Tracing layer to quickly inspect spans and events

tracing-texray First, a word of warning: This is alpha software. Don't run this in prod or anywhere where a panic would ruin your day. tracing-texray

Russell Cohen 23 Dec 3, 2022
Cakecutter - a utility tool that quickly sets up a project from a pre-built template

Cakecutter Create projects from pre-built cakes (templates)! Supports files, packages, content, running commands and more! Cakecutter is a utility too

Dhravya Shah 10 Jun 22, 2022
A Zellij plugin for quickly searching and switching tabs 🖤

?? room A Zellij plugin for quickly searching and switching between tabs. Usage Tab to cycle through tab list Up and Down to cycle through tab list En

Lucas 15 Jul 11, 2023
Zellij plugin to quickly navigate your panes (clone of nvim's harpoon)

harpoon A Zellij plugin for quickly searching and switching between tabs. Copy of the original harpoon for nvim. Usage a to add pane to list Up and Do

null 13 Aug 11, 2023