在Ruby下构建函数图的最简单方法是什么?有关特殊图形库的任何建议吗?
仅在Windows下更新: - (
更新2:发现以下宝石是目前为止的最佳解决方案https://github.com/clbustos/rubyvis
答案 0 :(得分:7)
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
}
}
}
答案 1 :(得分: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使用正确的宝石名称是我的关键。
答案 2 :(得分:1)
这是我的首选图表库:SVG::Graph
答案 3 :(得分:0)
我真的很喜欢tioga。它可以在乳胶中生成令人难以置信的高质量,出版物图表。
答案 4 :(得分:0)
像这样使用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();
答案 5 :(得分:0)
有Microsoft Excel。
如果是这样,Ruby on Windows博客可能会有用,问题tagged win32ole and ruby也是如此。