使用gnuplot,如何迭代ARG1、ARG2、ARGN?

使用gnuplot,如何迭代ARG1、ARG2、ARGN?,gnuplot,Gnuplot,我使用gnuplot脚本通过这样调用来绘制一些数据: gnuplot -p -c script.plt first.dat script.plt如下所示: set grid set yrange [0:1000] set xrange [-1:6] set xtic 1 rotate 90 plot ARG1 using (column(0)):2:3:4:xtic(1) with yerrorbars 我想传入更多数据,并将它们全部绘制在同一个图形上: gnuplot -p -c scri

我使用gnuplot脚本通过这样调用来绘制一些数据:

gnuplot -p -c script.plt first.dat
script.plt如下所示:

set grid
set yrange [0:1000]
set xrange [-1:6]
set xtic 1 rotate 90
plot ARG1 using (column(0)):2:3:4:xtic(1) with yerrorbars
我想传入更多数据,并将它们全部绘制在同一个图形上:

gnuplot -p -c script.plt first.dat second.dat
我可以通过以下方式实现:

set grid
set yrange [0:1000]
set xrange [-1:6]
set xtic 1 rotate 90
plot ARG1 using (column(0)):2:3:4:xtic(1) with yerrorbars, \
    ARG2 using (column(0)):2:3:4:xtic(1) with yerrorbars
但是我如何传递任意数量的数据来绘图呢

gnuplot -p -c script.plt first.dat second.dat third.dat
gnuplot -p -c script.plt first.dat second.dat third.dat fourth.dat ...
我知道可以使用plot进行迭代,但是可以在ARGS上进行迭代吗?比如:

plot for [arg in ARGS] arg using (column(0)):2:3:4:xtic(1) with yerrorbars

Gnuplot最多只支持10个
ARG
变量,即
ARG0,…,ARG9
(即使
ARGC
变量不受此限制)。作为一种解决方法,您可以将所有文件作为以空格分隔的字符串(假设文件名不包含空格字符)作为第一个参数传递

gnuplot -c script.plt "file1.dat file2.dat"
然后在Gnuplot中“解析”它:

plot for [i=1:words(ARG1)] word(ARG1, i) ...
编辑:

或者,可以将所有参数聚合到一个数组中(假设是最新版本的Gnuplot),然后在
plot
语句中使用此数组:

N = (9 < ARGC)?9:ARGC
array ARGV[N]

do for [i=1:N] {
  eval sprintf("ARGV[%d] = ARG%d", i, i);
}

print "found ", |ARGV|, " arguments"

plot for [i=1:|ARGV|] ARGV[i] ...
N=(9