Gruff graphs

Hi All,

I am struggling to do following and would someone could be help.
Following are my data

time1 = [ 1, 1.25, 3, 5]
y1 = [2.7, 3, 5, 10]

time2 = [ 0, 2, 5, 6, 7, 8, 9]
y2 = [10, 1, 3, 5, 6, 7, 12]

I want to graph y against a time line,

but issue is time1 0 position is not the same as time2 0 position in the
label hash.

Could someone please help me to figure out how to graph this?

Thanks

any help?

On Sep 23, 6:27 pm, “(r.*n){2}” [email protected] wrote:

hy1 = Hash.new
hy1.has_key?(time_all[i])
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y2 => (6, 5)
plotting y2 => (7, 6)
plotting y2 => (8, 7)
plotting y2 => (9, 12)

to make the times unique change:
time_all = [time1, time2].flatten.sort

to

time_all = [time1, time2].flatten.sort.uniq

On Sep 23, 5:27 pm, Ruwan B. [email protected] wrote:

any help?


Posted viahttp://www.ruby-forum.com/.

#!/usr/bin/ruby
time1 = [ 1, 1.25, 3, 5]
y1 = [2.7, 3, 5, 10]
hy1 = Hash.new
0.upto(time1.size-1) {|i| hy1[time1[i]] = y1[i] }

time2 = [ 0, 2, 5, 6, 7, 8, 9]
y2 = [10, 1, 3, 5, 6, 7, 12]
hy2 = Hash.new
0.upto(time2.size-1) {|i| hy2[time2[i]] = y2[i] }

time_all = [time1, time2].flatten.sort
0.upto(time_all.size-1).each do |i|
puts “plotting y1 => (#{time_all[i]}, #{hy1[time_all[i]]})” if
hy1.has_key?(time_all[i])
puts “plotting y2 => (#{time_all[i]}, #{hy2[time_all[i]]})” if
hy2.has_key?(time_all[i])
end

$./h2.rb
plotting y2 => (0, 10)
plotting y1 => (1, 2.7)
plotting y1 => (1.25, 3)
plotting y2 => (2, 1)
plotting y1 => (3, 5)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y2 => (6, 5)
plotting y2 => (7, 6)
plotting y2 => (8, 7)
plotting y2 => (9, 12)

(r.*n){2} wrote:

On Sep 23, 6:27�pm, “(r.*n){2}” [email protected] wrote:

hy1 = Hash.new
hy1.has_key?(time_all[i])
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y1 => (5, 10)
plotting y2 => (5, 3)
plotting y2 => (6, 5)
plotting y2 => (7, 6)
plotting y2 => (8, 7)
plotting y2 => (9, 12)

to make the times unique change:
time_all = [time1, time2].flatten.sort

to

time_all = [time1, time2].flatten.sort.uniq

Thanks so much for the help…I did something similar before you
posted this answer but your answer did help me to refactor my code.
Thank so much for your kind help.