{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Placing multiple plots on single layout\n",
"\n",
"Gnuplot have special layout for placing multiple plots on single layout and GnuplotRB supports this feature as well."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"require 'gnuplotrb'\n",
"include GnuplotRB\n",
"\n",
"sinx = Plot.new('sin(x)', title: 'Sin')\n",
"exp = Plot.new('exp(x)', title: 'Exp')\n",
"log = Plot.new('log(x)', title: 'Log')\n",
"sphere = Splot.new(\n",
" ['sin(u)*cos(v), sin(u)*sin(v), cos(u)', title: 'Sphere'],\n",
" parametric: true,\n",
" urange: 0..Math::PI,\n",
" vrange: 0..2*Math::PI,\n",
" title: 'sphere',\n",
" hidden3d: true,\n",
" isosamples: 30\n",
")\n",
"nil"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"#], @options=Hamster::Hash[:title => \"Sin\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, #], @options=Hamster::Hash[:title => \"Exp\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, #], @options=Hamster::Hash[:title => \"Log\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, # \"Sphere\"]>], @options=Hamster::Hash[:parametric => true, :urange => 0..3.141592653589793, :vrange => 0..6.283185307179586, :isosamples => 30, :hidden3d => true, :title => \"sphere\"], @already_plotted=true, @cmd=\"splot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>], @options=Hamster::Hash[:layout => [2, 2]], @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rows, cols = 2, 2\n",
"basic_four = Multiplot.new(sinx, exp, log, sphere, layout: [rows, cols])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also set one title for the whole layout."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"#], @options=Hamster::Hash[:title => \"Sin\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, #], @options=Hamster::Hash[:title => \"Exp\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, #], @options=Hamster::Hash[:title => \"Log\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, # \"Sphere\"]>], @options=Hamster::Hash[:parametric => true, :urange => 0..3.141592653589793, :vrange => 0..6.283185307179586, :isosamples => 30, :hidden3d => true, :title => \"sphere\"], @already_plotted=true, @cmd=\"splot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>], @options=Hamster::Hash[:layout => [2, 2], :title => [\"Multiplot example\"]], @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basic_four.title('Multiplot example')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can change layout size anytime (if it will have less cells than you have plots, they will be overriden by each other)."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"#], @options=Hamster::Hash[:title => \"Sin\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, # \"Sphere\"]>], @options=Hamster::Hash[:parametric => true, :urange => 0..3.141592653589793, :vrange => 0..6.283185307179586, :isosamples => 30, :hidden3d => true, :title => \"sphere\"], @already_plotted=true, @cmd=\"splot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>], @options=Hamster::Hash[:layout => [1, 2]], @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basic_two = Multiplot.new(sinx, sphere, layout: [1,2])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"#], @options=Hamster::Hash[:title => \"Sin\"], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, # \"Sphere\"]>], @options=Hamster::Hash[:parametric => true, :urange => 0..3.141592653589793, :vrange => 0..6.283185307179586, :isosamples => 30, :hidden3d => true, :title => \"sphere\"], @already_plotted=true, @cmd=\"splot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>], @options=Hamster::Hash[:layout => [2, 1]], @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"basic_two.layout(2,1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also use size and origin options instead of layout. It's useful when you need to have different cells."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"#], @options=Hamster::Hash[:size => [0.6, 1.0], :title => \"Sin\", :origin => [0, 0]], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, #], @options=Hamster::Hash[:size => [0.4, 0.5], :title => \"Log\", :origin => [0.6, 0]], @already_plotted=true, @cmd=\"plot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>, # \"Sphere\"]>], @options=Hamster::Hash[:parametric => true, :urange => 0..3.141592653589793, :size => [0.4, 0.5], :vrange => 0..6.283185307179586, :isosamples => 30, :hidden3d => true, :origin => [0.6, 0.5], :title => \"sphere\"], @already_plotted=true, @cmd=\"splot \", @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>], @options=Hamster::Hash[], @terminal=#&1\", @current_datablock=0, @err_array=[], @in=#>>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"minisinx = sinx.options(size: [0.6,1.0], origin: [0,0])\n",
"minilog = log.options(size: [0.4,0.5], origin: [0.6,0])\n",
"minisphere = sphere.options(size: [0.4,0.5], origin: [0.6,0.5])\n",
"Multiplot.new(minisinx, minilog, minisphere)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Ruby 2.1.2",
"language": "ruby",
"name": "ruby"
},
"language_info": {
"file_extension": "rb",
"mimetype": "application/x-ruby",
"name": "ruby",
"version": "2.1.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}