【发布时间】:2013-07-27 15:00:36
【问题描述】:
我正在尝试在 perl 中使用 gnuplot 脚本来获取一些绘图。我的data.dat 看起来像:
1 5 2
2 3 9
3 9 6
4 -4 8
5 -3 4
6 11 2
7 0 -3
8 -8 -2
9 1 0
10 22 0
我试过这个脚本:
#!/usr/bin/perl -w
use strict;
my $type="png";
open(my $GP,'| gnuplot');
print {$GP} << "__GNUPLOT__";
set style data lines
#set logscale y
set terminal $type
set output 'pic.$type'
plot "data.dat" u 1:2, "" u 1:3
__GNUPLOT__
close $GP;
我的目标是绘制对数刻度。由于负面数据,我想使用plot "data.dat" u 1:(abs($2)), "" u 1:(abs($3))。所以我想访问我的 perl-script 变量和 gnuplot 变量$2$3。不引用heredoc __GNUPLOT__ 对此不起作用。我发现了那些处理类似主题的帖子:
我不知道这个问题是否与 bash 相同。我还没有尝试过,但也会对那里感兴趣。我只是想了解更多关于管道、引用和不同类型变量的一般问题。
【问题讨论】:
-
有一个 Gnuplot 模块。它基本上完成了您在脚本中手动执行的操作并提供了一个界面。 Chart::Gnuplot。缺点是它需要 GhostScript 和 imagemagick 来生成 png 图像。我从来没有在没有这个模块的情况下使用过 gnuplot,所以我不知道这种行为是否正常。
-
如果可能的话,我会坚持使用 Gnuplot 的标准版本而不安装额外的模块。谢谢你的意见。
标签: perl variables gnuplot heredoc