用ruby绘制直方图百分比

用ruby绘制直方图百分比,ruby,gnuplot,histogram,Ruby,Gnuplot,Histogram,假设我有一个文件,每行有一个percetage,如下所示: 0.86 0.456 0.4389 0.56 0.69 0.468 0.46 0.368 0.9 ... 我想使用gnuplotgem在Ruby脚本中用这些数据绘制直方图。 它可能看起来像高斯钟 我怎样才能做到这一点呢?我在尝试gnuplot gem时玩得很开心:) 给定一个像这样的文件data.txt 0.86 0.456 0.4389 0.56 0.69 0.468 0.46 0.368 0.9 这个Ruby类应该做到以下几点:

假设我有一个文件,每行有一个percetage,如下所示:

0.86
0.456
0.4389
0.56
0.69
0.468
0.46
0.368
0.9
...
我想使用
gnuplot
gem在Ruby脚本中用这些数据绘制直方图。 它可能看起来像高斯钟


我怎样才能做到这一点呢?

我在尝试gnuplot gem时玩得很开心:)

给定一个像这样的文件
data.txt

0.86
0.456
0.4389
0.56
0.69
0.468
0.46
0.368
0.9
这个Ruby类应该做到以下几点:

require 'gnuplot'

class DataPlotter
  class << self
    def plot_data(data)
      Gnuplot.open do |gp|
        Gnuplot::Plot.new(gp) do |plot|
          plot.title  "Data Plot Example"
          plot.data << Gnuplot::DataSet.new(data) do |ds|
            ds.with = "linespoints"
            ds.notitle
          end
        end
      end
    end

    def load_data_from_file(filename)
      File.open(filename).readlines.map do |line|
        line.chomp.to_f
      end
    end

    def plot_file(filename)
      plot_data(load_data_from_file(filename))
    end
  end
end

DataPlotter.plot_file('data.txt')
需要“gnuplot”
类数据绘图仪

类阅读文档听起来是一个很好的开始…你尝试过什么吗?@Denis,是的,我尝试过,但是ruby就像一个包装器,所以我不知道如何指定一些选项。谢谢。我想重新措辞这个问题来说明你尝试了什么以及为什么它不起作用。。。