If you’ve ever needed to throw up a quick real-time plot from C++, it can be a hassle. Data visualization is a great way to sanity check your code, especially in scientific computing where you might have some long-running iterative code (for me it’s genetic algorithms).
A quick and dirty way to do this is to pipe out to a gnuplot process. It can update in real-time, and although there are some issues, it generally works pretty well. I just hacked up a lightweight C++ header that does this (note: only tested with linux), which I called plotpipe. Hopefully it’s useful to others as well (requires a gnuplot install to run).
Right now it just handles 1D and 2D datasets. Here’s an example of it plotting an animated moving window of a quadratic function:
#include <stdio.h> #include <stdlib.h> #include <vector> #include "graph.h" using namespace std; int main(int argc,char **argv) { plot p; for(int a=0;a<100;a++) { vector<float> x,y; for(int k=a;k<a+200;k++) { x.push_back(k); y.push_back(k*k); } p.plot_data(x,y); } return 0; }