Ruby:构建函数图

发布于 2024-08-07 10:06:47 字数 259 浏览 3 评论 0原文

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

更新: 仅在 Windows 下:-(

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

虚拟世界 2024-08-14 10:06:47

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

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
        }
    }
}
过期以后 2024-08-14 10:06:47

万一其他人遇到这个问题,我可以使用以下代码来使用 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

需要 ruby​​gems 并为 gnuplot 使用正确的 gem 名称对我来说是关键。

In case anyone else stumbles over this, I was able to use gnuplot using the following code:

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

Requiring rubygems and using the correct gem name for gnuplot was the key for me.

别再吹冷风 2024-08-14 10:06:47

这是我的常用图形库: SVG::Graph

This is my go-to graphing library: SVG::Graph

北方的韩爷 2024-08-14 10:06:47

我真的很喜欢 tioga。它可以在乳胶中生成令人难以置信的高质量、可供出版的图表。

I really like tioga. It can produce incredibly high quality, publication-ready graphs in latex.

与酒说心事 2024-08-14 10:06:47

使用 SVG::Graph ::行像这样:

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();

use SVG::Graph::Line like this:

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();
风月客 2024-08-14 10:06:47

有微软Excel。

如果是这样,Ruby on Windows 博客可能会很有用,问题也是如此 标记了 win32ole 和 ruby​​

There's Microsoft Excel.

If so, the Ruby on Windows blog may be useful, as are questions tagged win32ole and ruby.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文