In [1]:
require 'gnuplotrb'
include GnuplotRB
simple_plot = Plot.new(
['x*sin(x)', with: 'lines', lt: { rgb: 'blue', lw: 3 }],
xrange: -10..10,
title: 'Math function example',
ylabel: 'x',
xlabel: 'x*sin(x)'
)
Out[1]:
You can make GnuplotRB plots to be rendered into other formats using term option:
In [2]:
simple_plot.term('png')
Out[2]:
In [3]:
simple_plot.term('jpeg')
Out[3]:
In [4]:
simple_plot.term('dumb')
Out[4]:
In [5]:
simple_plot.term('dumb', size: [60,30])
Out[5]:
In [6]:
simple_plot.term('svg', fsize: '18')
Out[6]:
Of course plot may be created with term option already set:
In [7]:
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,
term: ['png', size: [600, 800]]
)
Out[7]:
GnuplotRB allows to plot into png/svg/jpeg/gif files with handy #to_|format name|
methods. They take 2 arguments: path to image file (optional, if none given, file contents will be returned from method) and options. This kind of methods are available for all Plottable objects except Animation (Dataset, Plot, Splot, Multiplot). You may see all possible formats in gnuplot doc p. 190. You can also check which terminals are handled by your gnuplot installation:
In [8]:
Settings.available_terminals
Out[8]:
In [9]:
Plot.new('sin(x)').to_png('plot.png')
File.open('plot.png')
Out[9]:
In [10]:
svg_contents = Plot.new('sin(x)').to_svg(size: [600, 600])
IRuby.display(svg_contents, mime: 'image/svg+xml')