Plotting realtime data with GNUPLOT
Hi!
I am trying to write a C program to plot data from a bluetooth device. GNUPLOT seemed to be the way to go. So far i got: Code:
set xrange [0:200] Is there a way to get around this, and watch the data in real time? //John |
Quote:
I had to do something similar once upon a once and I wound up gathering data for some period of time then spitting it out to GNUPLOT (with the execlp function I think, have a look at the manual page), killing that after a time and looping back to regenerate. Worked OK and most systems are fast enough nowadays that you don't really notice the "blink" when the old chart goes away and the new one pops up. There might be some sort of Java thing you can do or a JavaScript thing to an HTML page but the GNUPLOT way isn't a bad idea either -- what works works, eh? Hope this helps some. |
It is fundamentally impossible to do that, because Gnuplot is a batch operation -- that is you first have to feed all the data before it can create a plot.
The solution would be to use not a single process loop, but a dual loop. Single means that you produce the data, and run Gnuplot immediately in the hope it will display the plot while data is produced. Dual loop means: one process collects the data and writes it to a file periodically. Then a second process picks up the data, and periodically creates the plot. This is not different as what tronayne wrote, it is just a more generic description. Since you already seems to have your data acquisition process running, you have a number of choices for the Gnuplot loop: a bash script periodically calling display, or integrate it is a web page, where Gnuplot would produce the plot and Javascript refreshes it periodically. As a matter of fact this start to look like a triple loop. If the plot is real simple you could consider using the Tk toolkit with Tcl or Python. Tk has some graph widgets. jlinkels |
Hi guys!
Thanks for taking an interest. Just to make shure that I'm not confusing anyone by using the words realtime and plot, here is a snippet of my C application. This function opens up a pipe to gnuplot and initiates the graph: (Basically stolen from the GNU Guile tutorial) Code:
static FILE* start_gnuplot() Code:
fprintf( global_output, "plot \"-\" notitle\n" ); Does that make sense? If this is not possible in gnuplot, I will probably do it in Qt... |
All times are GMT -5. The time now is 03:43 PM. |