我想要一個情節聲明循環幾個對函數情節。聲明的順序很重要,因爲它會按正確的順序創建透支。優雅的方式來循環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