# Gruff and labeling

**URL:** <https://www.ruby-forum.com/t/gruff-and-labeling/154155>\
**Category:** Ruby\
**Created:** [November 25, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/gruff-and-labeling/154155 "2008-11-25T22:38:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![silentd3at4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@silentd3at4](https://www.ruby-forum.com/u/silentd3at4)\
**Post date:** [November 25, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/gruff-and-labeling/154155/1 "2008-11-25T22:38:53Z")

</div>

I have everything done my output goes to a graph everything is fine  
except now i need to put labels on the x axis for each decade. So  
currently Y-axis Says: population X-axis says: years and they Y-Axis has  
the years posted on the side for each row. BUT how do i get 1951 - 2004  
to post on the bottom the graph (every decade not ever year)

Heres wat i got so far plz any help appreciated?

ARGV.each do |arg|  
countriesString \<\< “,"#{arg.to\_s}"”  
form\_params[‘my\_countries’] = “#{countriesString}”  
#FORM PARAMS COMPLETED

#COLLECT DATA  
results =  
Net::HTTP.post\_form(URI.parse(‘[http://pwt.econ.upenn.edu/php\_site/...pwt62/pwt62\_retrieve.php](http://pwt.econ.upenn.edu/php_site/...pwt62/pwt62_retrieve.php)’),  
form\_params)  
parse\_page = Hpricot(results.body)  
popData\_H = (parse\_page/“pre”).inner\_html  
popCSV = CSV.parse(popData\_H.to\_s {|f| f.read})  
#END COLLECT DATA  
#PREPARE TO GRAPH  
label = arg  
popdata = popCSV.map { |x| x[3].to\_i }  
if popdata[2]% 10 == 0 || popdata[2] == 1951 || popdata[2] == 2004  
labels = popdata  
end  
popdata.delete(0)  
pg.data(label, popdata)  
pg.x\_axis\_label = “Years”  
pg.y\_axis\_label = “Population”  
countriesString = ‘’  
end

pg.write(‘population\_graph.png’)

---

<div class="post-metadata">

**Author:** ![silentd3at4](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@silentd3at4](https://www.ruby-forum.com/u/silentd3at4)\
**Post date:** [November 25, 2008, 11:03pm UTC](https://www.ruby-forum.com/t/gruff-and-labeling/154155/2 "2008-11-25T23:03:22Z")

</div>

::Realized I didnt have year info gathered from my CSV so i added that  
but still need help on how to put the dates(Decades) as the x-col values  
=P

require ‘net/http’  
require ‘rubygems’  
require ‘gruff’  
require ‘csv’  
require ‘hpricot’

pg = Gruff::Line.new  
form\_params = Hash.new  
countriesString = ‘’

#GET FORM PARAMS  
form\_params = {  
‘my\_vars’ =\> ‘,+POP’,  
‘my\_yrs’ =\>  
‘1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004’,  
‘selected\_vars’ =\> ‘POP’,  
‘format\_selected’ =\> ‘csv’  
}

ARGV.each do |arg|  
countriesString \<\< “,"#{arg.to\_s}"”  
form\_params[‘my\_countries’] = “#{countriesString}”  
#FORM PARAMS COMPLETED

#COLLECT DATA  
results =  
Net::HTTP.post\_form(URI.parse(‘[http://pwt.econ.upenn.edu/php\_site/pwt62/pwt62\_retrieve.php](http://pwt.econ.upenn.edu/php_site/pwt62/pwt62_retrieve.php)’),  
form\_params)  
parse\_page = Hpricot(results.body)  
popData\_H = (parse\_page/“pre”).inner\_html  
popCSV = CSV.parse(popData\_H.to\_s {|f| f.read})  
#END COLLECT DATA  
#PREPARE TO GRAPH  
label = arg  
popdata = popCSV.map { |x| x[3].to\_i }  
yeardata = popCSV.map { |x| x[2].to\_i }  
popdata.delete(0)  
yeardata.delete(0)  
yeardata.each do |x|  
if x % 10 == 0 || x == 1951 || x == 2004  
labels = yeardata[2]  
end  
end  
pg.data(label, popdata)  
pg.x\_axis\_label = “Years”  
pg.y\_axis\_label = “Population”  
countriesString = ‘’  
end  
puts pg.methods.sort  
pg.write(‘population\_graph.png’)
