require 'pilot-gnuplot'
include Gnuplot
# To use gnuplot this way iRuby should be modified.
# For some reason there are also problems with
# svg's so I'm using png in all other examples.
cartesian = 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)'
)
# github doesn't show svg so I inserted here a png too
cartesian.to_png('cartesian.png')
File.open('cartesian.png')
polar = Plot.new(
['abs(sin(3*t))', with: 'filledcurves', lt: { rgb: 'red' }],
title: 'Plot in polar example',
polar: true,
samples: 500
)
polar.to_png('polar.png', size: [500, 500])
File.open('polar.png')
parametric = Plot.new(
['1.5*cos(t) - cos(30*t), 1.5*sin(t) - sin(30*t)', title: 'Parametric curve', lw: 2],
title: 'Parametric plot example',
parametric: true,
samples: 1000,
xrange: -3..3,
yrange: -3..3
)
parametric.to_png('parametric.png', size: [500, 500])
File.open('parametric.png')