Ruby:构建功能图

gmi*_*ile 6 ruby plot function

在Ruby下构建函数图的最简单方法是什么?有关特殊图形库的任何建议吗?

更新:仅在Windows下:-(

更新2:发现以下gem是目前为止的最佳解决方案https://github.com/clbustos/rubyvis

Bre*_*ugh 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
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 抱歉,这不是很明显,但是您已经安装了gnuplot吗?红宝石只是绑定,AFAIK (2认同)