Coder Social home page Coder Social logo

node-gnuplot's Introduction

node-gnuplot

A super-thin wrapper around gnuplot for node.js

example

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);

methods

var gnuplot = require('gnuplot')

gnuplot()

Spawn a new gnuplot process and return a duplex stream combining stdout and stdin.

gnuplot.print(data, options={})

Write data to stdin of the gnuplot process. If the stream should be closed after the write, pass {end: true} as options.

gnuplot.println(data, options={})

Same as gnuplot.print(data + '\n', options)

gnuplot.set(data, options={})

Same as gnuplot.println('set ' + data, options)

gnuplot.unset(data, options={})

Same as gnuplot.println('unset ' + data, options)

gnuplot.plot(data, options={})

Same as gnuplot.println('plot ' + data, options)

gnuplot.splot(data, options={})

Same as gnuplot.println('splot ' + data, options)

gnuplot.replot(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'));

install

With npm do:

npm install gnuplot

You need to have gnuplot installed. On OSX you can do this with homebrew:

brew install gnuplot

license

ISC

node-gnuplot's People

Contributors

davvo avatar tyrasd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-gnuplot's Issues

Callback before image generation finish

Hi, I'm using gnuplot in order to create an image and send it in Telegram, the function it's like this:

function img_generation (result, callback) {

  let plot = gnuplot()
    .set('terminal png medium size 400,300')
    .set('output "out.png"')
    .set('title "Isotopic distribution"')
    .unset('key') // no legend
    .set('border 3')
    .set('xlabel "m/z (Da)"')
    .set('ylabel "Intensity (%)"')
    .set('ytics nomirror') // hide ticks left
    .set('xtics nomirror') // hide ticks top
    .set('grid xtics lw 1 lc rgb "#dddddd"')
    .set('grid ytics lw 1 lc rgb "#dddddd"')
    .set('xrange [' + result.chartXFrom + ':' + result.chartXTo + ']')
    .set('yrange [0:120]');

  result.xy.forEach( (point) => {
    plot.set('arrow from ' + point[0] + ',0 to ' + point[0] + ',' + point[1] * 100 + ' nohead lw 2 lc rgb "blue"');
  });
  plot.plot('sin(x) lc rgb "white"');
  plot.end( (err) => {
    if (err) console.error(err);

   // here I send the image
    bot.sendPhoto(fromId, 'out.png');
  });
}

The problem is that the image it's trying to be sended before it's generated, do you have any idea why it's that happening?

Thanks, I love your module ๐Ÿ‘

Error handling?

Is there any error handling in this? What happens when an instruction (string) given to gnuplot creates and error and fails to produce a plot? I'm not seeing any obvious way to get feedback if something fails. Thanks!

add pause support

if you add 'pause', then running from command line can open x11 windows.

in gnuplot.js
['set', 'unset', 'plot', 'splot', 'replot','pause'].forEach(function (name) {

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.