Joel VanderWerf
6/4/2009 7:56:00 PM
Jason Lillywhite wrote:
> 2. How do I apply your idea to methods within an embedded array block
> such as "plot.data" from my code:
>
> plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
> ds.with = "lines"
> end
>
> which has methods such as ds.linewidth, ds.title, etc? I tried multiple
> things like creating 2 hashes but can't get my hash values to pass into
> the embedded array. Thank you!
Something like this?
require 'gnuplot'
class Data2d
def self.plot(x, y, options={})
Gnuplot.open do |gp|
Gnuplot::Plot.new( gp ) do |plot|
options.each {|opt,val| plot.send opt, val}
ds_options = options[:ds]
plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
ds_options.each {|opt,val| ds.send opt, val}
end
end
end
end
end
Data2d.plot(x,y,:x_label=>"Time",:y_label=>"Values", :title=>"My First
Plot", :ds => {:with => "lines"})
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407