I need to plot data in real time, reading a file over and over and
update a the screen. How to implement reread and replot?
Are you on Windows? Or, which OS?
I do something similar as you want to do (on Windows): I write data
coming from an ADC to Disk (using a c-programm), update line by line
each 1..60 seconds, and I read this file with Ruby and send the data
from Ruby to gnuplot, doing 2d-plots, updating the plot each time Ruby
reads a new data line.
@gp = "path_to_pgnuplot.exe"
... @pipe = IO.popen(@gp, "w")
sleep 2 @pipe.puts "set xtics\n" @pipe.puts "set ytics\n" @pipe.puts "set style data #{ @linestyle }\n" @pipe.puts "set grid\n"
... @pipe.puts "plot \"-\" title 'CH1', \"-\" title 'CH2', \"-\" title
'CH3', \"-\" title 'CH4', \"-\" title 'CH5'"
... @pipe.close
On Windows, I have a timeout problem with gnuplot;
# "Anti-timeout" workaround; put this at the very beginning of your
programm
puts "Starting dummy-instance of wgnuplot"
tmppipe = IO.popen(@gp, "w")
sleep 10
tmppipe.close
The suggestion works perfect for me. I used a separate thread and a
queue to communicate when new data i available instead of sleep.
It seems more flexible to use pipes than the wrapper, but the wrapper
maybe gives nicer code.