#include #include #include #include #include #include "util/gnuplot.h" #include "util/util.h" class PlotGaussian{ public: void test(){ int i, j; Gnuplot gp1, gp2; gp1 << "clear\n"; gp1 << "set multiplot\n"; gp1 << "set style data dots\n"; gp1.flush(); /* gp2 << "set multiplot\n"; gp2 << "set range [0:1] [0:1]\n"; gp2 << "set noautoscale\n"; gp2.flush(); */ for(i = 0; i < 100; i++){ gp1 << "plot [-5:5] [-5:5] '-' title 'test'\n"; //gp2 << "plot '-'\n"; for(j = 0; j < 1000; j++){ double x, y; //x = drand(); //y = drand(); x = rand_regularized(0., 1.); y = rand_regularized(0., 1.); //std::cout << x << ", " << y << std::endl; gp1 << x << " " << y << "\n"; //gp2 << x << " " << y << "\n"; } gp1 << "e\n"; gp1.flush(); /* gp2 << "e\n"; gp2.flush(); */ } gp1 << "pause 5\n"; gp1.flush(); /* gp2 << "pause 5\n"; gp2.flush(); */ } }; class PlotGaussian3D{ public: void test(){ int i; Gnuplot gp; gp << "clear\n"; gp << "set multiplot\n"; gp << "set style data dots\n"; gp.flush(); gp << "splot [-5:5] [-5:5] [-5:5] '-' title 'test'\n"; for(i = 0; i < 1000; i++){ double x, y, z; x = rand_regularized(0., 1.); y = rand_regularized(0., 1.); z = rand_regularized(0., 1.); //std::cout << x << ", " << y << std::endl; gp << x << " " << y << " " << z << "\n"; } gp << "e\n"; gp.flush(); gp << "pause 10\n"; gp.flush(); } }; class AnimationPlot{ private: void use_dq(){ Gnuplot gp; deque dq; char buf[1024]; std::strstream strstm(buf, sizeof(buf), std::ios::in | std::ios::out); gp << "clear\n"; gp << "set style data lines\n"; //gp << "set noautoscale\n"; //gp << "set range [0:100] [-5:5]\n"; gp << "set nokey\n"; gp.flush(); for(int i = 0; i < 1000; i++){ if(dq.size() > 70){dq.pop_front();} dq.push_back(rand_regularized(0., 1.)); strstm << "plot [0:100] [-5:5] '-'\n"; int index = 0; for(deque::iterator it = dq.begin(); it < dq.end(); it++){ strstm << index++ << " " << *it << "\n"; } strstm << "e\n" << std::ends; gp << buf; gp.flush(); strstm.seekp(0); } gp << "pause 10\n"; gp.flush(); } void force(){ Gnuplot gp; gp << "clear\n"; //gp << "set multiplot\n"; gp << "set style data lines\n"; gp.flush(); for(int i = 0; i < 1000; i++){ int from = i < 70 ? 0 : i - 70; gp << "plot [" << from << ":" << from + 100 << "] [-5:5] '-' title 'test'\n"; gp << i << " " << rand_regularized(0., 1.) << "\n"; gp << "e\n"; gp.flush(); } gp << "pause 10\n"; gp.flush(); } public: void test(){ use_dq(); //force(); } }; int main(){ //(new PlotGaussian())->test(); //(new PlotGaussian3D())->test(); (new AnimationPlot())->test(); return 0; }