x = (1..600).map { |i| i/100.0 }
y = x.map { |xx| Math.sin(xx ** 2.3) * Math.exp(-xx) }
nil
First lets generate a file
File.open('tons_of_data', 'w') { |f| (1..300).each { |i| f.puts "#{x[i]} #{y[i]}" } }
1..300
and plot it
require 'pilot-gnuplot'
include Gnuplot
graph = Plot.new(['tons_of_data', title: 'Tons of data', with: 'lines'])
graph.to_png('tons.png')
File.open('tons.png')
Now we can just append file and replot out graph
File.open('tons_of_data', 'a') { |f| (301..600).each { |i| f.puts "#{x[i]} #{y[i]}" } }
graph.to_png('tons.png')
File.open('tons.png')
x0 = x[0..200]
y0 = y[0..200]
updatable_plot = Plot.new([[x0,y0], with: 'lines', title: 'Before update'])
updatable_plot.to_png('updatable.png')
File.open('updatable.png')
x1 = x[201..600]
y1 = y[201..600]
updated_plot = updatable_plot.update_dataset(data: [x1,y1], title: 'After update')
updated_plot.to_png('updated.png')
File.open('updated.png')
This way is expensive because data is piped to gnuplot each time you want to replot it, but updating data does not affect original Plot:
updatable_plot.to_png('updatable_new.png')
File.open('updatable_new.png')
Dataset boolean option 'file' corresponds to using temporary file for storage data being plotted.
x0 = x[0..400]
y0 = y[0..400]
updatable_file_plot = Plot.new([[x0,y0], with: 'lines', title: 'Before update', file: true])
updatable_file_plot.to_png('updatable_file.png')
File.open('updatable_file.png')
x1 = x[401..600]
y1 = y[401..600]
updated_file_plot = updatable_file_plot.update_dataset(data: [x1,y1], title: 'After update')
updated_file_plot.to_png('updated_file.png')
File.open('updated_file.png')
Be careful: updating data stored in temp file affects original Plot:
updatable_file_plot.to_png('updatable_file_after.png')
File.open('updatable_file_after.png')