我正在尝试在几对函数图上创建一个 plot 语句循环。语句的顺序很重要,因为它会以正确的顺序创建透支。
#!/usr/bin/gnuplot -persist
datfile="overdraw.dat"
num=3
skip=40
set table datfile
g(x,t)=exp(-x**2+{0,1}*2*t*x)
set samples 501
plot [-2:2][0:5] for [ii=0:num] real(g(x,ii))
unset table
xspeed=0.1
yspeed=0.3
## this works but creates overdraw in the wrong order
#plot [-2:2] \
# for [ii=0:num] datfile index ii u ($1+xspeed*ii):($2-yspeed*ii) not w l lt ii lw 8 \
#, for [ii=0:num] datfile index ii every skip u ($1+xspeed*ii):($2-yspeed*ii) not w p lt ii pt 7 ps 4 \
#
set macro
## this works but is cumbersome
plotstring="NaN not"
do for [ii=0:num] {
plotstring=plotstring.sprintf(", \"%s\" index %i u ($1+xspeed*%i):($2-yspeed*%i) not w l lt %i lw 8", datfile, ii, ii, ii, ii)
plotstring=plotstring.sprintf(", \"%s\" index %i every skip u ($1+xspeed*%i):($2-yspeed*%i) not w p lt %i pt 7 ps 4", datfile, ii, ii, ii, ii)
}
plot [-2:2] @plotstring
## this doesn't work because the for loop only applies to the first statement
#plotboth='datfile index ii u ($1+xspeed*ii):($2-yspeed*ii) not w l lt ii lw 8\
#, datfile index ii every skip u ($1+xspeed*ii):($2-yspeed*ii) not w p lt ii pt 7 ps 4'
#plot [-2:2] for [ii=0:num] @plotboth
## this gives an error message
plot [-2:2] for [ii=0:num] { \
datfile index ii u ($1+xspeed*ii):($2-yspeed*ii) not w l lt ii lw 8\
, datfile index ii every skip u ($1+xspeed*ii):($2-yspeed*ii) not w p lt ii pt 7 ps 4 \
}
如您所见,我通过附加到包含绘图语句的字符串使其以正确的顺序工作。但是,如果能够在我的示例末尾所示的情节语句周围加上括号,那就太好了。
提交多个绘图/重新绘图语句似乎不是一种选择,因为这会在某些终端(例如 postscript)中创建页面。我也会认为 multiplot 很麻烦。也许我忽略了一种优雅的语法?