A super-thin wrapper around gnuplot for node.js
var gnuplot = require('gnuplot');
gnuplot()
.set('term png')
.set('output "out.png"')
.set('title "Some Math Functions"')
.set('xrange [-10:10]')
.set('yrange [-2:2]')
.set('zeroaxis')
.plot('(x/4)**2, sin(x), 1/x')
.end();
You can use streams!
var data = fs.createReadStream('input.dat'),
out = fs.createWriteStream('output.svg'),
plotter = gnuplot().set('term svg');
data.pipe(plotter).pipe(out);
var gnuplot = require('gnuplot')
Spawn a new gnuplot process and return a duplex stream combining stdout
and stdin
.
Write data to stdin of the gnuplot process. If the stream should be closed after the write, pass {end: true}
as options.
Same as gnuplot.print(data + '\n', options)
Same as gnuplot.println('set ' + data, options)
Same as gnuplot.println('unset ' + data, options)
Same as gnuplot.println('plot ' + data, options)
Same as gnuplot.println('splot ' + data, options)
Same as gnuplot.println('replot ' + data, options)
All of the above functions returns the gnuplot object and can be chained together:
gnuplot()
.set('term png')
.unset('output')
.plot('[-6:6] sin(x)')
.end();
To automatically call end() on the input stream after a command, pass {end: true}
as options:
gnuplot()
.set('term png')
.unset('output')
.plot('[-6:6] sin(x)', {end: true})
.pipe(fs.createWriteStream('out.png'));
With npm do:
npm install gnuplot
You need to have gnuplot installed. On OSX you can do this with homebrew:
brew install gnuplot
ISC