我想要一个情节声明循环几个对函数情节。声明的顺序很重要,因为它会按正确的顺序创建透支。优雅的方式来循环gnuplot 4.6中的几个语句?
#!/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 \
}
正如你所看到的,我通过附加到一个持有plot语句的字符串来使它按正确的顺序工作。但是,如果能够在我的例子末尾所示的情节陈述中加上括号,那就太好了。
提交几个plot/replot语句似乎不是一个选项,因为它在某些终端(例如postscript)中创建了一些页面。我也认为多插槽也很麻烦。也许有一种我忽略的优雅语法?
这个问题仍然相关吗?你能提供一个你的输入的例子吗? (我可能会花更多时间尝试创建一个,而不是提出答案)。 – Schorsch 2013-06-05 17:01:02
@Schorsch,请取消我上面MWE中的各种注释块,以解决问题所在。 我的MWE产生的数据直至您可以使用的'unset data'语句。 '##这工作,但很麻烦' 是产生我喜欢的输出块,但我不喜欢编码。 '##这给出了一个错误消息' 是我想如何做事,因为它更系统。 这可能只是在gnuplot的未来版本中才会起作用,但我想问一下现在是否有办法做类似的事情(即明确地控制循环中的透支顺序)。 – Andreas 2013-06-05 17:56:26