Numo::Gnuplot : Gnuplot interface for Ruby

Alpha version under development.

Although there are many other Gnuplot interface libraries for Ruby, none of them have so simple interface as to show an XY data plot by just typing:

plot x,y

Numo::Gnuplot achieves this by providing only one class which has the same inteface as Gnuplot command line, and no other class which causes extra learning costs.


Add this line to your application's Gemfile:

gem 'numo-gnuplot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install numo-gnuplot



  • All examples require to load Numo::Gnuplot class:
require "numo/gnuplot"
  • The first example showing how it works.
gp =
gp.set title:"Example Plot"
gp.plot "sin(x)",w:"lines"
  • You can omit receiver. do
  set title:"Example Plot"
  plot "sin(x)",w:"lines"
  • The same thing in short.
Numo.gnuplot do
  set title:"Example Plot"
  plot "sin(x)",w:"lines"
  • In these examples, the following command lines are send to Gnuplot.
set title "Example Plot"
plot sin(x) w lines
  • Interactive plotting with IRB:
$ irb -r numo/gnuplot
irb(main):001:0> pushb Numo.gnuplot
irb(gnuplot):002:0> set t:"Example Plot"
irb(gnuplot):003:0> plot "sin(x)",w:"lines"
  • Plotting X-Y data stored in arrays.
require "numo/gnuplot"

x = (0..100).map{|i| i*0.1}
y ={|i| Math.sin(i)}

Numo.gnuplot do
  set title:"X-Y data plot"
  plot x,y, w:'lines', t:'sin(x)'
  • Plotting X-Y data stored in NArrays.
require "numo/gnuplot"
require "numo/narray"

x = Numo::DFloat[0..100]/10
y = Numo::NMath.sin(x)

Numo.gnuplot do
  set title:"X-Y data plot in Numo::NArray"
  plot x,y, w:'lines', t:'sin(x)'
  • Multiple data are separated by Hash or put into Array.
require 'numo/gnuplot'
require 'numo/narray'
NM = Numo::NMath

n = 60
x = Numo::DFloat[-n..n]/n*10

Numo.gnuplot do
  set title:"multiple data series"

  # Hash-separated form
  plot x,NM.sin(x), {w:'points',t:'sin(x)'}, x,x*NM.sin(x),{w:"lines",t:'x*sin(x)'}

  # or Array-separated form
  plot [x,NM.sin(x), w:'points',t:'sin(x)'], [x,x*NM.sin(x),w:"lines",t:'x*sin(x)']
  # (here last item in each Array should be Hash, to distinguish from data array)

  • Plotting 2D arrays in 3D.
require 'numo/gnuplot'
require 'numo/narray'

n = 60
x = (,n).seq/n-0.5)*30
y = (,1).seq/n-0.5)*30
r = Numo::NMath.sqrt(x**2+y**2) + 1e-10
z = Numo::NMath.sin(r)/r

Numo.gnuplot do
  set title:'2D data plot'
  set dgrid3d:[60,60]
  splot z, w:'pm3d', t:'sin(r)/r'


Numo::Gnuplot is compatible with IRuby.

  • Embedding a plot into iRuby Notebook. do
  plot "sin(x)"
  • The same thing in short.
Numo.noteplot do
  plot "sin(x)"

Gnuplot methods

Numo::Gnuplot class methods succeeded from Gnuplot commands:

  • clear
  • exit
  • fit(*args)
  • help(topic)
  • load(filename)
  • pause(*args)
  • plot(*args)
  • quit
  • reflesh
  • replot
  • reset(option)
  • set(*options)
  • show(option)
  • splot(*args)
  • unset(*options)
  • update(*files)

Numo::Gnuplot class methods renamed from Gnuplot commands:

  • raise_plot(plot_window) -- 'raise' command
  • lower_plot(plot_window) -- 'lower' command

Numo::Gnuplot-specific methods:

  • debug_off -- turn off debug print.
  • debug_on -- turn on debug print.
  • run(command_line) -- send command-line string to Gnuplot directly.
  • output(filename,[term,*opts]) -- output current plot to file. If term is omitted, an extension in filename is regarded as a term name. This invokes the next commands; ruby set terminal:[term,*opts] set output:filename; refresh
  • var(name) -- returns variable content in the Gnuplot context.

See API doc for more.


Bug reports and pull requests are welcome on GitHub at