Gnuplot have special layout for placing multiple plots on single layout and GnuplotRB supports this feature as well.
require 'gnuplotrb' include GnuplotRB sinx = Plot.new('sin(x)', title: 'Sin') exp = Plot.new('exp(x)', title: 'Exp') log = Plot.new('log(x)', title: 'Log') sphere = Splot.new( ['sin(u)*cos(v), sin(u)*sin(v), cos(u)', title: 'Sphere'], parametric: true, urange: 0..Math::PI, vrange: 0..2*Math::PI, title: 'sphere', hidden3d: true, isosamples: 30 ) nil
To use this feature in GnuplotRB you just need to pass several Plot or Splot objects to constructor of Multiplot class. It's recommended to give him layout size too.
rows, cols = 2, 2 basic_four = Multiplot.new(sinx, exp, log, sphere, layout: [rows, cols])
You can also set one title for the whole layout.
You can change layout size anytime (if it will have less cells than you have plots, they will be overriden by each other).
basic_two = Multiplot.new(sinx, sphere, layout: [1,2])
You can also use size and origin options instead of layout. It's useful when you need to have different cells.
minisinx = sinx.options(size: [0.6,1.0], origin: [0,0]) minilog = log.options(size: [0.4,0.5], origin: [0.6,0]) minisphere = sphere.options(size: [0.4,0.5], origin: [0.6,0.5]) Multiplot.new(minisinx, minilog, minisphere)