1

Is it possible in gruff to draw vertical marker lines, or does it only do horizontal lines?

If the latter, is there another ruby graph gem that can draw proper x,y graphs?

dcnicholls
  • 391
  • 1
  • 5
  • 15

2 Answers2

0

From further exploration, it looks like gruff does not do full scientific x,y charts. I explored gnuplot for Ruby, and it does what I'm looking for. The documentation for the ruby gnuplot is a bit limited, and you need to do a bit of sleuthing to work out how to do things like change line width and color, which are not the same commands as in the standard gnuplot. You need to install the ruby gnuplot gem, and also the regular gnuplot (easily done using something like homebrew, apt-get etc) as the ruby gem is a wrapper for the standard gnuplot.

dcnicholls
  • 391
  • 1
  • 5
  • 15
0

Steps to use gnuplot rubygem:

  1. Install XQuartz from here

  2. Install gnuplot with homebrew: brew install gnuplot --with-x11

  3. Install gnuplot rubygem: gem install gnuplot

After you follow the above steps, you are ready to use gnuplot in your ruby program to generate 2-D graphs (x,y graphs). Here is a working version of a ruby program which generates correct graphs when run:

require 'gnuplot'

Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|

    plot.title  "Array Plot Example"
    plot.xlabel "x"
    plot.ylabel "x^2"

    x = (0..50).collect { |v| v.to_f }
    y = x.collect { |v| v ** 2 }

    plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
      ds.with = "linespoints"
      ds.notitle
    end
  end
end
K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110