使用gnuplot在节点js中绘制和保存数字

我在节点js的bashsubprocess中使用gnuplot来绘制一些数据并保存graphics。 这是我的代码到目前为止:

var term = require('child_process').spawn('bash'); term.stdin.write('gnuplot -p\n'); term.stdin.write('set key outside\n'); term.stdin.write('set term png\n'); term.stdin.write('set output "plot1.png"\n') term.stdin.write('plot for [col=2:4] "results" using 1:col with points title columnheader\n'); term.stdin.write('set output "plot2.png"\n') term.stdin.write('plot for [col=5:7] "results" using 1:col with points title columnheader\n'); 

这是更正确和最快的方式吗? 无论如何,我可以使它更紧凑和简单? 另外,当我在node.js脚本中运行这个脚本时,当我运行这个脚本的时候,这个脚本不会退出。 如何解决这个问题?

解:

直接产生gnuplot var term = require('child_process').spawn('gnuplot'); 而不是bash。

删除term.stdin.write('gnuplot -p\n'); (-p标志使得gnuplot窗口持久化,但是没有必要这样做,因为在这种情况下,graphics被打印到PNG图像上)

term.stdin.write('exit\n')添加term.stdin.write('exit\n')

    Interesting Posts