【问题标题】:How to give command line arguments to gnuplot [duplicate]如何为gnuplot提供命令行参数[重复]
【发布时间】:2013-06-05 15:01:37
【问题描述】:

我正在编写一个脚本来一次从多个文件中绘制多个文件。我还想保存与数据文件对应的每个绘图的输出。我们如何将这两个参数都提供给 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 脚本运行。

任何帮助表示赞赏。

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

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

    【讨论】:

    • 你找到-e选项的官方文档了吗?我正在寻找几个小时,仍然没有运气。
    • @Wolf 您可以在 gnuplot 文档的“批处理/交互式操作”部分找到它。
    • @Christoph 谢谢,但这仍然有点令人困惑:我找到了同一版本文档的两个版本,Batch/Interactive OperationBatch/Interactive_Operation - Gnuplot: An Interactive Plotting Program。它是如此基本,以至于我无法相信为什么会这样隐藏这些信息。
    • @Wolf 我同意该信息。应该更容易找到。幸运的是,我们有 *!至于不同的文档,它们对应不同的gnuplot版本。
    【解决方案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 中,并将 gnuplot 文件存储在 sample.gp 文件中。

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

    【讨论】:

    • 这太可怕了。请不要这样做。使用 -e