GnuplotRB plots may be embedded into iRuby notebooks as images (terminals svg, png, jpeg and pngcairo are supported) or plain text (dumb terminal). By default GnuplotRB will use svg:
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)'
)
You can make GnuplotRB plots to be rendered into other formats using term option:
simple_plot.term('png')
simple_plot.term('jpeg')
simple_plot.term('dumb')
Math function example
8 +-+---------------+-----------------+----------------+---------------+-+
+ + + + + + + + +
6 +-+ + + x*sin(x)++-----+-+
| + + + + |
| | + + | |
4 +-+ + | | + +-+
| | + + | |
2 +-++ + + ++-+
| | | ++++++ ++++++ | | |
| + + + +++ +++ + + + |
0 +-+ | + ++++ + | +-+
|| + + + + ||
-2 +-+ + + + + +-+
|| + + + + ||
|+ + + + + +|
-4 +-+ ++ ++ ++ ++ +-+
+ + + + +
-6 +-+---------------+-----------------+----------------+---------------+-+
-10 -5 0 5 10
x*sin(x)
To specify some image params like canvas size or font you can pass options to term:
simple_plot.term('dumb', size: [60,30])
Math function example
8 +-+----------+------------+------------+----------+-+
+ + + + + + + + +
| | + x*sin(x) +-----+ |
6 +-+ + | | + +-+
| | + + | |
| + | | + |
| | + + | |
4 +-++ | | ++-+
| | + + | |
| | | | | |
2 +-+ + +++ +++ + +-+
| | | + ++ ++ + | | |
| | + + ++ ++ + + | |
0 +-+ | + +++ + | +-+
| | + + + + | |
|| | + + | ||
-2 +-+ + | | + +-+
|| | + + | ||
|| + + + + ||
|+ + + + + +|
-4 +-+ + + + + +-+
| ++ ++ |
+ + + + +
-6 +-+----------+------------+------------+----------+-+
-10 -5 0 5 10
x*sin(x)
simple_plot.term('svg', fsize: '18')
Of course plot may be created with term option already set:
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]]
)