首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从php调用Gnuplot?

从php调用Gnuplot?
EN

Stack Overflow用户
提问于 2011-06-29 00:58:44
回答 2查看 4.3K关注 0票数 1

我想知道如何在我的php脚本中使用exec命令来调用Gnuplot。

首先,我将给出一些背景背景:

我已经写了几个php文件,它们从数据库中抓取数据,并将记录的值放入文本文件中,以便gnuplot可以读取它们。在此基础上,我有了第二个php文件,它生成了一个gnuplot脚本,该脚本具有用于创建图形的适当指针。

我可以手动转到c:/gnuplot/gnuplot/binary/gnuplot.exe graph.txt并手动生成图形,但我不知道如何自动生成它。

Linux和Windows的建议都会很有帮助!我正在编写它并在windows上测试它,但是一旦它被修复,它就会被送到我们的Linux服务器上。

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-06-29 01:07:19

要在Linux机器上执行gnuplot,可以使用php中的exec()函数。我不确定你到底想对输出做什么,但是exec绝对可以运行这个程序。

票数 1
EN

Stack Overflow用户

发布于 2012-06-09 20:34:05

这是我用来让PHP和gnuplot对话的一些非常旧的代码,很久以前它甚至不支持PNG输出,所以使用了。这还没有在Windows上测试过:

代码语言:javascript
复制
// Assuming data has been written to $data_file...

$image_file = tempnam("/tmp","gnuplotout");
$gplot_start = date("y/m/d", $start_date);
$gplot_finish = date("y/m/d", $finish_date);
$gnuplot_cmds = <<< GNUPLOTCMDS
set term pbm color small
set output "$image_file"
set size 1, 1
set title "Title"
set xlabel "Date"
set ylabel "EUR"
set xdata time
set timefmt "%y/%m/%d"
set xrange ["$gplot_start":"$gplot_finish"]
set format x "%d/%m"
set nokey
plot "$data_file" using 1:2 with lines
GNUPLOTCMDS;
$gnuplot_cmds .= "\n";

// Start gnuplot
if(!($pgp = popen("/usr/bin/gnuplot", "w"))){
    # TODO Handle error
    exit;
}
fputs($pgp, $gnuplot_cmds);
pclose($pgp);
header("Content-Type: image/png");
passthru("/usr/bin/pnmtopng $image_file");

// Clean up and exit
unlink($data_file);
unlink($image_file);
exit;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6510263

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档