gnuplot
Version:
node gnuplot wrapper
106 lines (70 loc) • 2.19 kB
Markdown
node-gnuplot
============
A super-thin wrapper around [gnuplot](http://www.gnuplot.info/) for node.js
``` 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!
``` js
var data = fs.createReadStream('input.dat'),
out = fs.createWriteStream('output.svg'),
plotter = gnuplot().set('term svg');
data.pipe(plotter).pipe(out);
```
``` js
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:
``` js
gnuplot()
.set('term png')
.unset('output')
.plot('[-6:6] sin(x)')
.end();
```
To automatically call [end()](http://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback) on the input stream after a command, pass `{end: true}` as options:
``` js
gnuplot()
.set('term png')
.unset('output')
.plot('[-6:6] sin(x)', {end: true})
.pipe(fs.createWriteStream('out.png'));
```
With [npm](https://npmjs.org) do:
```
npm install gnuplot
```
You need to have [gnuplot](http://www.gnuplot.info/) installed. On OSX you can do this with [homebrew](http://brew.sh/):
```
brew install gnuplot
```
ISC