ruby-numo / numo-gnuplot

Gnuplot wrapper for Ruby/Numo
BSD 3-Clause "New" or "Revised" License
51 stars 8 forks source link
gnuplot narray numo plot plotting ruby ruby-numo

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.

Installation

Add this line to your application's Gemfile:

gem 'numo-gnuplot'

And then execute:

$ bundle

Or install it yourself as:

$ gem install numo-gnuplot

Demo

Usage

require "numo/gnuplot"
gp = Numo::Gnuplot.new
gp.set title:"Example Plot"
gp.plot "sin(x)",w:"lines"
Numo::Gnuplot.new.instance_eval do
  set title:"Example Plot"
  plot "sin(x)",w:"lines"
end
Numo.gnuplot do
  set title:"Example Plot"
  plot "sin(x)",w:"lines"
end
set title "Example Plot"
plot sin(x) w lines
$ 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"
require "numo/gnuplot"

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

Numo.gnuplot do
  set title:"X-Y data plot"
  plot x,y, w:'lines', t:'sin(x)'
end
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)'
end
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)

end
require 'numo/gnuplot'
require 'numo/narray'

n = 60
x = (Numo::DFloat.new(1,n).seq/n-0.5)*30
y = (Numo::DFloat.new(n,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'
end

IRuby

Numo::Gnuplot is compatible with IRuby.

Numo::Gnuplot::NotePlot.new do
  plot "sin(x)"
end
Numo.noteplot do
  plot "sin(x)"
end

Gnuplot methods

Numo::Gnuplot class methods succeeded from Gnuplot commands:

Numo::Gnuplot class methods renamed from Gnuplot commands:

Numo::Gnuplot-specific methods:

See API doc for more.

Related Work

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ruby-numo/numo-gnuplot.