Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is an easy / easiest way to *plot* a std::vector<double>?

I'm looking for something like:

 std::vector<double> X = some_math_function( );
 somenamespace :: plot(  Wrapper( X ) ); // pop-up and display a graph of X on y-axis, 1 to X.size() on x-axis. 

Obviously there are heavier-weight methods like setting up gnu-plot or whatever, and I've used the stuff in VTK charts. I just want a stupid, ghetto, plot to appear. This is for coarse debug checking things like "is the vector even changing? does it suddenly jerk when I move the camera?" and so on.

like image 389
peter karasev Avatar asked Oct 17 '25 11:10

peter karasev


1 Answers

If this is for debugging why not just output the vector to a delimited file and plot in excel or gnuplot or something as a separate step?

so something like

//untested
ofstream myfilestream("myfile");
std::copy(X.begin(), X.end(), std::ostream_iterator<double>(myfilestream, '\n');

then just plot the file in what ever tool you like e.g.

gnuplot
plot "myfile" with lines
like image 171
jk. Avatar answered Oct 19 '25 02:10

jk.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!