Gruff and labeling

T

Trick Nick

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'),
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')
 
T

Trick Nick

::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'),
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')
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top