-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp.rb
51 lines (48 loc) · 1.2 KB
/
gp.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'gnuplot'
# Usage:
#nb.times { |i|
# w=f(i)
# h=g(i)
# lw << w
# lh << h
# li << i
#}
#plot("Generations",["W",li,lw, "H",li,lh],"lines")
#
#nb.times { |i|
# w=f(i)
# h=g(i)
# l << [i,h,w]
#}
#rplot("Generations",l,["W","H"],"lines")
def plot(title,llxy, type)
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.title title
plot.xrange "[0:#{llxy.first(2).last.max}]"
llxy.each_slice(3) {|name,lx,ly|
plot.data << Gnuplot::DataSet.new([lx, ly]) do |ds|
ds.with = type
ds.title= name
end
}
end
end
end
def rplot(title,lxy, labels, type)
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.title title
#plot.xrange "[0:#{llxy.first(2).last.max}]"
labels.size.times {|index|
lx= lxy.map {|a|a.first}
ly= lxy.map {|a|a[1+index]}
label=labels[index]
plot.data << Gnuplot::DataSet.new([lx, ly]) do |ds|
ds.with = type
ds.title= label
end
}
end
end
end