Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Gruff graphs

Reply
Thread Tools

Gruff graphs

 
 
Ruwan Budha
Guest
Posts: n/a
 
      09-23-2010
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
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Ruwan Budha
Guest
Posts: n/a
 
      09-23-2010
any help?

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
(r.*n){2}
Guest
Posts: n/a
 
      09-23-2010
On Sep 23, 5:27*pm, Ruwan Budha <ruw...@gmail.com> 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)
 
Reply With Quote
 
(r.*n){2}
Guest
Posts: n/a
 
      09-24-2010
On Sep 23, 6:27*pm, "(r.*n){2}" <perl2r...@gmail.com> wrote:
> On Sep 23, 5:27*pm, Ruwan Budha <ruw...@gmail.com> 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)


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

to

time_all = [time1, time2].flatten.sort.uniq
 
Reply With Quote
 
Ruwan Budha
Guest
Posts: n/a
 
      09-25-2010
(r.*n){2} wrote:
> On Sep 23, 6:27�pm, "(r.*n){2}" <perl2r...@gmail.com> 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
gruff graphs and labels Ruwan Budha Ruby 0 09-20-2010 11:55 PM
Displaying gruff graphs Victor Reyes Ruby 9 04-01-2008 04:01 PM
Gruff UTF-8 problem erhan Ruby 0 07-04-2006 07:54 AM
Testing Rails: problem running a Gruff sample Richard Lionheart Ruby 4 02-22-2006 01:19 AM
Problems with Gruff hoyhoy@gmail.com Ruby 8 11-21-2005 01:24 AM



Advertisments
 



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 52 53 54 55 56 57