Gruff graphs

R

Ruwan Budha

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
 
R

(r.*n){2}

any help?

#!/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] = y1 }

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] = y2 }

time_all = [time1, time2].flatten.sort
0.upto(time_all.size-1).each do |i|
puts "plotting y1 => (#{time_all}, #{hy1[time_all]})" if
hy1.has_key?(time_all)
puts "plotting y2 => (#{time_all}, #{hy2[time_all]})" if
hy2.has_key?(time_all)
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

(r.*n){2}

any help?

#!/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] = y1 }

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] = y2 }

time_all =  [time1, time2].flatten.sort
0.upto(time_all.size-1).each do |i|
   puts "plotting y1 => (#{time_all}, #{hy1[time_all]})" if
hy1.has_key?(time_all)
   puts "plotting y2 => (#{time_all}, #{hy2[time_all]})" if
hy2.has_key?(time_all)
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)


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

to

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

Ruwan Budha

(r.*n){2} said:
hy1 = Hash.new
hy1.has_key?(time_all)
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top