With Gordon James Miller’s rgplot package you can use gnuplot from within Ruby. This example shows how you can use gnuplot for displaying a 3D plot of the values in a two-dimensional array.

#!/usr/bin/env ruby
require 'hornetseye'
require 'gnuplot'
include Hornetseye
class Sequence_
def to_gsplot
retval = ""
for j in 0...shape[1]
for i in 0...shape[0]
retval += " #{self[i,j]}"
end
retval += "\n"
end
retval += "\n"
retval
end
def plot
Gnuplot.open do |gp|
Gnuplot::SPlot.new( gp ) do |plot|
plot.pm3d
plot.hidden3d
plot.palette 'defined ( 0 "black", 51 "blue", 102 "green", ' +
'153 "yellow", 204 "red", 255 "white" )'
plot.data << Gnuplot::DataSet.new( self ) do |ds|
ds.with = 'lines'
ds.matrix = true
end
end
end
end
end
s = Sequence.sfloat( 60 ).indgen!( 0.5 - 60 / 2 ) / Math::PI
sinc = MultiArray.tensor( 2 ) do |i,j|
r = Math.hypot s[i], s[j]
Math.sin( r ) / r
end
sinc.plot