2D plot

With Gordon James Miller’s rgplot package you can use gnuplot from within Ruby.  This example shows how you can plot the histogram of an image.

See also

#!/usr/bin/env ruby
require 'hornetseye'
require 'gnuplot'
include Hornetseye
def plot( *arrs )
  options = arrs.last.is_a?( Hash ) ? arrs.pop : {}
  { :title => [ nil ] * arrs.size }.merge options
  title = options[ :title ]
  title = [ title ] unless title.is_a? Array
  Gnuplot.open do |gp|
    Gnuplot::Plot.new( gp ) do |plot|
      arrs.zip( title ).each do |arr,t|
        x = (0...arr.size).collect { |v| v.to_f }
        plot.data << Gnuplot::DataSet.new( [ x, arr ] ) do |ds|
          ds.with = "linespoints"
          if t
            ds.title = t
          else
            ds.notitle
          end
        end
      end
    end
  end
  nil
end
raise "Syntax: plot.rb <input image>" if ARGV.size != 1
img = MultiArray.load_ubyte ARGV[0]
plot img.hist( 256 ), :title => [ 'Histogram' ]
With Gordon James Miller’s rgplot package you can use gnuplot from within Ruby.
Close