Replot in ruby gnuplot

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?

require ‘gnuplot’
class Plot

Plot a surface of the data in file in realtime

def realTimeSurfacePlot (plotFile, title, xLabel, yLabel, zLabel)
Gnuplot::open do |gp|
Gnuplot::SPlot.new(gp) do |plot|
plot.title title
plot.set “xlabel %s” %xLabel
plot.set “ylabel %s” %yLabel
plot.set “zlabel %s” %zLabel
plot.set “grid”
plot.set “pm3d”
plot.data = [
Gnuplot::DataSet.new("""+plotFile+""") { |ds|

}

]
end
end
end

Thank you

Lars

Hi Lars,

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.

For reading the file I use: file-tail.

For “real-time” plotting with gnuplot I took a lot from here and
transfered it to Ruby:

http://www.lysium.de/blog/index.php?/archives/234-Plotting-data-with-gnuplot-in-real-time.html

I open a pipe to pgnuplot.exe:

@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

Hope it helps,
Axel

Thanks, I’ll give it a try tomorrow when I’m on a Windows box

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.

Thanks

Lars