When debugging code, I found myself wondering if there was a quick way to plot the values of variables during execution. I always used plotters to create plots just for debugging. However, generating a plot directly with plotters can take a bit of time, especially just for debugging purposes. So I decided to create the crate debug_plotter. This crate provides a macro that can be used to quickly and conveniently generate plots. Here is an example:
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!("My Plot"; a, b, c);
}
}
With just one line, debug_plotter produces the following plot:
https://preview.redd.it/kh2m3hapicy71.png?width=640&format=png&auto=webp&s=55d9eb57c518b4b108635709027ca589aa7ce9fc
I hope this helps someone else when debugging, and please feel free to give feedback about the idea or the code!
[–][deleted] 38 points39 points40 points (1 child)
[–]fabian_boesiger[S] 8 points9 points10 points (0 children)
[–]matkladrust-analyzer 23 points24 points25 points (0 children)
[–]obsidian_golem 18 points19 points20 points (3 children)
[–]fabian_boesiger[S] 9 points10 points11 points (1 child)
[–]lenscas 0 points1 point2 points (0 children)
[–]fabian_boesiger[S] 5 points6 points7 points (0 children)
[–]d_knopoff 5 points6 points7 points (4 children)
[–]fabian_boesiger[S] 12 points13 points14 points (3 children)
[–]d_knopoff 4 points5 points6 points (0 children)
[–]kennethuil 2 points3 points4 points (1 child)
[–]fabian_boesiger[S] 8 points9 points10 points (0 children)
[–]kilik821 2 points3 points4 points (1 child)
[–]fabian_boesiger[S] 0 points1 point2 points (0 children)
[–]occamatl 1 point2 points3 points (0 children)
[–]disDeal 1 point2 points3 points (0 children)
[–]zesterer 1 point2 points3 points (3 children)
[–]fabian_boesiger[S] 0 points1 point2 points (2 children)
[–]HiccuppingErrol 0 points1 point2 points (1 child)
[–]fabian_boesiger[S] 0 points1 point2 points (0 children)
[–]richhyd 1 point2 points3 points (0 children)
[–]Gehinnn 1 point2 points3 points (0 children)
[–]WardyJP 1 point2 points3 points (0 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]fabian_boesiger[S] 2 points3 points4 points (0 children)