In [1]:
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.
In [2]:
rows, cols = 2, 2
basic_four = Multiplot.new(sinx, exp, log, sphere, layout: [rows, cols])
Out[2]:
You can also set one title for the whole layout.
In [3]:
basic_four.title('Multiplot example')
Out[3]:
You can change layout size anytime (if it will have less cells than you have plots, they will be overriden by each other).
In [4]:
basic_two = Multiplot.new(sinx, sphere, layout: [1,2])
Out[4]:
In [5]:
basic_two.layout(2,1)
Out[5]:
You can also use size and origin options instead of layout. It's useful when you need to have different cells.
In [6]:
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)
Out[6]: