Ruby:构建一个功能图 [英] Ruby: building a plot of function

查看:97
本文介绍了Ruby:构建一个功能图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



update:仅适用于Windows: - (



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

解决方案



<$ p $ ($ p $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' testgnu.pdf
plot.terminalpdf颜色尺寸27cm,19cm

plot.xrange[-10:10]
plot.titleSin Wave Example
plot.ylabelx
plot.xlabelsin(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 =冲动
ds.linewidth = 4
}
}
}


What's the easiest way to build a plot of a function under Ruby? Any suggestions as to the special graphical library?

update: under windows only :-(

update 2: found the following gem as a best solution so far https://github.com/clbustos/rubyvis

解决方案

Is gnuplot a possible option?:

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
        }
    }
}

这篇关于Ruby:构建一个功能图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆