Ruby:构建函数图
在Ruby下构建函数绘图的最简单方法是什么?关于特殊图形库有什么建议吗 更新:仅在windows下:-(Ruby:构建函数图,ruby,function,plot,Ruby,Function,Plot,在Ruby下构建函数绘图的最简单方法是什么?关于特殊图形库有什么建议吗 更新:仅在windows下:-( 更新2:发现以下gem是迄今为止最好的解决方案这是我的图形库:是一个可能的选项吗?: require 'gnuplot.rb' Gnuplot.open { |gp| Gnuplot::Plot.new( gp ) { |plot| plot.output "testgnu.pdf" plot.terminal "pdf colour size 27c
更新2:发现以下gem是迄今为止最好的解决方案这是我的图形库:是一个可能的选项吗?:
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.rb'
Gnuplot.open{| gp|
Gnuplot::Plot.new(gp){| Plot|
plot.output“testgnu.pdf”
plot.terminal“pdf颜色尺寸27cm,19cm”
plot.xrange“[-10:10]”
plot.title“正弦波示例”
plot.ylabel“x”
plot.xlabel“sin(x)”
plot.data我真的很喜欢。它可以用乳胶制作出高质量、便于出版的图形。使用如下:
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();
如果其他人对此有任何疑问,我可以使用以下代码使用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”
Gnuplot.open do|gp|
Gnuplot::Plot.new(gp)do | Plot|
plot.xrange“[-10:10]”
plot.title“正弦波示例”
plot.ylabel“x”
plot.xlabel“sin(x)”
plot.data有微软的Excel
如果是这样的话,博客可能会很有用,问题也一样。gnuplot很好,但不知怎么的,我无法运行示例。只是安装了gem。在Windows上运行1.8.6。有什么想法/需要的插件吗?如果不是很明显,很抱歉,但是你已经安装了gnuplot本身吗?Ruby位只是绑定,AFAIKIn对@Brent的响应:这里是t下载gnuplot的页面:这是唯一一个对我有效的页面。但是-我可以生成连续函数图而不是虚线吗?tioga仅适用于POSIX OS系列:-(事实上,tioga现在可以在windows上工作,尽管MikTeX安装的要求可能很痛苦。