在 Ruby 下构建函数图的最简单方法是什么?关于特殊图形库的任何建议?
更新:仅在 Windows 下:-(
更新 2:发现以下 gem 作为迄今为止的最佳解决方案https://github.com/clbustos/rubyvis
在 Ruby 下构建函数图的最简单方法是什么?关于特殊图形库的任何建议?
更新:仅在 Windows 下:-(
更新 2:发现以下 gem 作为迄今为止的最佳解决方案https://github.com/clbustos/rubyvis
是gnuplot一个可能的选择吗?:
require 'gnuplot.rb'
Gnuplot.open { |gp|
    Gnuplot::Plot.new( gp ) { |plot|
        plot.output "testgnu.pdf"
        plot.terminal "pdf colour size 27cm,19cm"
        plot.xrange "[-10:10]"
        plot.title  "Sin Wave Example"
        plot.ylabel "x"
        plot.xlabel "sin(x)"
        plot.data << Gnuplot::DataSet.new( "sin(x)" ) { |ds|
            ds.with = "lines"
            ds.linewidth = 4
        }
        plot.data << Gnuplot::DataSet.new( "cos(x)" ) { |ds|
            ds.with = "impulses"
            ds.linewidth = 4
        }
    }
}
    万一其他人对此感到困惑,我可以使用以下代码使用 gnuplot:
require 'rubygems'
require 'gnuplot' 
Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
    plot.xrange "[-10:10]"
    plot.title  "Sin Wave Example"
    plot.ylabel "x"
    plot.xlabel "sin(x)"
    plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
      ds.with = "lines"
      ds.linewidth = 4
    end
  end
end
要求 rubygems 并为 gnuplot 使用正确的 gem 名称是我的关键。
这是我的首选图形库:SVG::Graph
我真的很喜欢tioga。它可以在 Latex 中生成令人难以置信的高质量、可发布的图表。
像这样使用SVG::Graph::Line:
require 'SVG/Graph/Line'
  fields = %w(Jan Feb Mar);
  data_sales_02 = [12, 45, 21]
  data_sales_03 = [15, 30, 40]
  graph = SVG::Graph::Line.new({
          :height => 500,
          :width => 300,
    :fields => fields,
  })
  graph.add_data({
          :data => data_sales_02,
    :title => 'Sales 2002',
  })
  graph.add_data({
          :data => data_sales_03,
    :title => 'Sales 2003',
  })
  print "Content-type: image/svg+xml\r\n\r\n";
  print graph.burn();
    有微软 Excel。
如果是这样,Windows博客上的 Ruby 可能会很有用,标记为 win32ole 和 ruby 的问题也很有用。