# Gruff graphs

**URL:** <https://www.ruby-forum.com/t/gruff-graphs/195472>\
**Category:** Ruby\
**Created:** [September 23, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/gruff-graphs/195472 "2010-09-23T15:55:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 23, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/gruff-graphs/195472/1 "2010-09-23T15:55:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 23, 2010, 11:26pm UTC](https://www.ruby-forum.com/t/gruff-graphs/195472/2 "2010-09-23T23:26:59Z")

</div>

any help?

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 24, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/gruff-graphs/195472/3 "2010-09-24T15:55:47Z")

</div>

On Sep 23, 6:27 pm, “(r.\*n){2}” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 24, 2010, 12:30am UTC](https://www.ruby-forum.com/t/gruff-graphs/195472/4 "2010-09-24T00:30:58Z")

</div>

On Sep 23, 5:27 pm, Ruwan B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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)

---

<div class="post-metadata">

**Author:** ![woow](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7bcc69/32.png) [@woow](https://www.ruby-forum.com/u/woow)\
**Post date:** [September 25, 2010, 6:06am UTC](https://www.ruby-forum.com/t/gruff-graphs/195472/5 "2010-09-25T06:06:16Z")

</div>

(r.\*n){2} wrote:

> On Sep 23, 6:27ï¿½pm, “(r.\*n){2}” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
