如何向gnuplot传递命令行参数

5

我正在编写一个脚本,逐个从多个文件中绘制多个文件。我还想保存每个图的输出与数据文件相对应。我们如何将两个参数都传递给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脚本运行。
非常感谢您的帮助。
2个回答

8

你找到了-e选项的官方文档吗?我已经搜索了几个小时,但还没有找到。 - Wolf
@Wolf,你可以在gnuplot文档的“批处理/交互操作”部分找到它。 - Christoph
@Christoph 谢谢您,但还是有点困惑:我发现同一个版本的文档有两个版本,Batch/Interactive OperationBatch/Interactive_Operation - Gnuplot: An Interactive Plotting Program。这是如此基础的信息,我无法理解为什么会隐藏起来。 - Wolf
1
@Wolf 我同意信息应该更容易找到。幸运的是我们有stackoverflow!至于不同的文档,它们对应不同的gnuplot版本。 - cabad

-2

尝试这个简单的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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接