A
Armin Armbruster
Hi,
I've been using gnuplot for the last little while to plot data and I
really like it. So far I've been processing my data with ruby and
generated a csv file, that I then read from a gnuplot script.
This works fine, but I want to take out the extra step of going through
a csv file.
I've been trying to use the gnuplot gem (v. 2.2), however I've been
running into problems with large data sets.
Here are two sample programs, that do essentially the same. The
difference is that the first one calls gnuplot directly, whereas the
second one generates a gnuplot script file, that can be used by gnuplot.
Version 1: Calling gnuplot directly from ruby.
(Note my gnuplot path is: "c:/Program Files/gnuplot/bin/pgnuplot.exe")
Gnuplot.open do |gp|
Gnuplot:lot.new( gp ) do |plot|
x = (0..1500).collect { |v| v.to_f }
y = x.collect { |v| v ** 2 }
plot.data =[ Gnuplot:ataSet.new( [x, y] ) do |ds|
ds.with = "linespoints"
ds.notitle
end
]
end
end
Version 2: Generating a gnuplot script, that afterward can be called by
gnuplot
File.open( "gnuplot.dat", "w") do |gp|
Gnuplot:lot.new( gp ) do |plot|
x = (0..1500).collect { |v| v.to_f }
y = x.collect { |v| v ** 2 }
plot.data = [Gnuplot:ataSet.new( [x, y] ) { |ds|
ds.with = "linespoints"
ds.title = "Array data"
}]
end
end
Unfortunately the first version doesn't really work. For some reason the
data gets corrupted. It's almost like gnuplot can't keep up fast enough
reading the data. I've been playing around with the array size. For
smaller data sets (a few hundred points) version 1 works fine, but as
array size increases to 700-800 points I see this problem happening.
I can work with version 2 for now, but it seems a bit like a kludge to
me, ideally I'd like to not go through an intermediate file.
Any ideas would be appreciated.
Thanks,
Armin
I've been using gnuplot for the last little while to plot data and I
really like it. So far I've been processing my data with ruby and
generated a csv file, that I then read from a gnuplot script.
This works fine, but I want to take out the extra step of going through
a csv file.
I've been trying to use the gnuplot gem (v. 2.2), however I've been
running into problems with large data sets.
Here are two sample programs, that do essentially the same. The
difference is that the first one calls gnuplot directly, whereas the
second one generates a gnuplot script file, that can be used by gnuplot.
Version 1: Calling gnuplot directly from ruby.
(Note my gnuplot path is: "c:/Program Files/gnuplot/bin/pgnuplot.exe")
Gnuplot.open do |gp|
Gnuplot:lot.new( gp ) do |plot|
x = (0..1500).collect { |v| v.to_f }
y = x.collect { |v| v ** 2 }
plot.data =[ Gnuplot:ataSet.new( [x, y] ) do |ds|
ds.with = "linespoints"
ds.notitle
end
]
end
end
Version 2: Generating a gnuplot script, that afterward can be called by
gnuplot
File.open( "gnuplot.dat", "w") do |gp|
Gnuplot:lot.new( gp ) do |plot|
x = (0..1500).collect { |v| v.to_f }
y = x.collect { |v| v ** 2 }
plot.data = [Gnuplot:ataSet.new( [x, y] ) { |ds|
ds.with = "linespoints"
ds.title = "Array data"
}]
end
end
Unfortunately the first version doesn't really work. For some reason the
data gets corrupted. It's almost like gnuplot can't keep up fast enough
reading the data. I've been playing around with the array size. For
smaller data sets (a few hundred points) version 1 works fine, but as
array size increases to 700-800 points I see this problem happening.
I can work with version 2 for now, but it seems a bit like a kludge to
me, ideally I'd like to not go through an intermediate file.
Any ideas would be appreciated.
Thanks,
Armin