2013-06-05 48 views
4

我正在编写一个脚本来一次绘制多个文件中的多个文件。我也想保存每个对应于数据文件的图的输出。我们怎样才能给GNUPlot两个参数。例如:示例GNUPlot脚本如何给命令行参数gnuplot

set xlabel "a" 
set ylabel "b" 
set zlabel "c" 
set term postscript 
set output "??" #'??' implies variable i.e. take file name from commandline 
splot "??" with points,"??" with points #'??' implies variable i.e. take file name from commandline 

并且此脚本将由另一个生成所需文件名的shell脚本运行。

任何帮助表示赞赏。

回答

8

您还可以使用gnuplot的-e命令行选项。看到这个问题的例子:How to pass command line argument to gnuplot?

+0

您是否找到'-e'选项的任何官方文档?我正在寻找几个小时,仍然没有运气。 – Wolf

+0

@Wolf您可以在gnuplot文档中的“批处理/交互式操作”部分找到它。 – Christoph

+0

@Christoph感谢,但它仍然有点令人困惑:我发现了同一版本的文档的两个版本,[批处理/交互操作](http://gnuplot.sourceforge.net/docs_4.2/node46.html)和[批处理/ Interactive_Operation - Gnuplot:交互式绘图程序](http://soc.if.usp.br/manual/gnuplot-doc/htmldocs/Batch_002fInteractive_005fOperation.html)。这是如此根本,我不能相信为什么这些信息是这样隐藏的。 – Wolf

-3

试试这个简单的bash脚本

#!/bin/bash 

file="output.png" 
infile1="$1" 
infile2="$2" 

echo " 
set xlabel \"a\" 
set ylabel \"b\" 
set zlabel \"c\" 
set term postscript 
set output \"$file\" #'??' implies variable i.e. take file name from commandline 
splot \"$infile1\" with points,\"$infile2\" with points #'??' implies variable i.e. take file name from commandline 
" > sample.gp && gnuplot sample.gp 

,并调用它像./script data.txt data2.txt 你将不得不存储在output.png输出和存储在sample.gp文件gnuplot的文件。

即使每次绘制的文件数量不同,添加更多文件以绘图也很容易。您也可以将您的.gp文件存储在不同的输出中。

+5

这很可怕。请不要这样做。使用-e – easytiger