1

csv ファイル「harvest.csv」があり、列の 1 つに日付が含まれています。ここに私が来たものがあります(plot.rb):

require 'csv'
require 'gnuplot'

days = Array.new
mg = Array.new

csv = CSV.open("../data/harvest.csv", headers: :first_row, converters: :numeric)
csv.each do |row|
  days << row[1]
  mg << row[3]
end


dates = []
days.each {|n| dates << Date.strptime(n,"%Y-%m-%d")}

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
    plot.timefmt "'%Y%m%d'"
    plot.title  "Best Harvest Day"
    plot.xlabel "Time"
    **plot.xrange "[('2013-04-01'):('2013-06-01')]"**
    plot.ylabel "Harvested"


    plot.data << Gnuplot::DataSet.new( [dates,mg] ) do |ds|
      ds.with = "linespoints"
      ds.title = "Pollen harvested"
    end
  end
end

plot.rb を実行すると、エラーが発生します。

 line 735: Can't plot with an empty x range!

[日付] を別のものに変換する必要がありますか?

4

1 に答える 1