Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: sfeam Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Realtime plot-C++ showing previous 5 values Followup-To: comp.graphics.apps.gnuplot Date: Thu, 12 Apr 2012 23:16:44 -0700 Organization: gnuplot development team Lines: 64 Message-ID: References: <4c34c399-5c77-4085-892e-2124e3b63337@gh10g2000pbc.googlegroups.com> Reply-To: sfeam@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit Injection-Date: Fri, 13 Apr 2012 06:16:47 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="3mhAfh4CeAIeL3OKnPexDA"; logging-data="19622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mG+sKuhChWAhImhshWr+E" User-Agent: KNode/4.4.9 Cancel-Lock: sha1:KrJwqZIMszJP/N4WkILTacTtKkk= Xref: csiph.com comp.graphics.apps.gnuplot:1034 lakskant wrote: > Dear all, > > I have successfully integrated my c++ program which scans values from > a laser scanner and gnuplot in real time. It can plot the values in a > single window. I used this code. > > string command = "set multiplot \n" ; > char *path = "\"C:\\Program Files\\gnuplot\\bin\\gnuplot\""; > > gp = _popen(path , "w"); > > if (gp == NULL) > > return -1; > > fprintf(gp,"set multiplot\n"); Why multiplot? > fprintf(gp,"set origin 0,0\n"); > if (scancount ==1) > { > fprintf(gp, "plot '-' u 1:2 w points\n"); > } > else > { > fprintf(gp, "plot '-' u 1:2 w points\n"); > } These two commands seem to be the same. Typo? > for (int i=0;i<80;i++) > fprintf(gp, "%lf %lf\n",afx[i],afy[i]); > fprintf(gp, "e\n"); > fflush(gp); > > > Now I want to only display last 5 scan values on a same window. My > solution is to write the values in a temp file and plotting it from > there. > > Is there any better efficient solution. I am afraid I don't quite understand what you are trying to do. For one thing I don't understand whether there is only one scanned data set, or a new one every few seconds, or what. Yes, you could write the data to a separate file and then have gnuplot read the data from the file. You could even replace the contents of the file asynchronously and have gnuplot refresh the display by sending it a "replot" command. As to doing something special with the previous N data points, you might have a look at: http://gnuplot.sourceforge.net/demo/running_avg.html