【问题标题】:Drag and drop script for gnuplotgnuplot 的拖放脚本
【发布时间】:2016-08-15 22:08:35
【问题描述】:

我有一些数据想在 gnuplot 中绘制。为了能够绘制它们,我编写了一个名为“plot_A.gp”的脚本。我在其中设置轴值、标签和输出终端。
为了不为每个数据文件修改它,我想知道是否有可能使脚本能够处理拖放文件。

作为示例脚本:

set xrange [0 to 100]
set xlabel "x-axis"
set ylabel "y-axis"
set terminal eps
set output %1.pdf
plot %1 using 1:($2*$2) with lines

如何将%1 设置为我刚刚放到脚本中的文件名?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    请在 gnuplot 提示符下使用 call 而不是 load 执行脚本。 call 最多接受 10 个参数。在 gnuplot 5.0 之前,这些参数被称为 $0, $1, ..., $9。

    在 gnuplot 4.6 中,您的脚本将如下所示:

    datafile="$0"
    outputfile="$0".".pdf"
    set xrange [0 to 100]
    set xlabel "x-axis"
    set ylabel "y-axis"
    plot "hello" using 1:($$2*$$2) with lines
    set terminal eps
    set output outputfile
    replot
    set terminal wxt
    set output
    

    因为$2 指的是脚本的第三个参数,所以要访问第二列,请改用$$2。或者,您也可以使用1:(column(2)*column(2))

    你可以这样称呼它。

    gnuplot> call "plot_A.gp" "hello"
    

    这将绘制文件“hello”中的数据并创建一个名为“hello.pdf”的 pdf。作为最佳实践,我还将终端重置回wxt

    从 gnuplot 5.0 开始,不推荐使用 $0、$1 等。相反,您应该使用特殊变量 ARG0、ARG2、...、ARG9。我无权访问 gnuplot 5.0。但我认为你只需要使用ARG0 而不是$0。请您参考How to pass command line argument to gnuplot?的这个答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 2020-03-12
      • 1970-01-01
      • 1970-01-01
      • 2022-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多