2013-05-10 174 views
3

我想要一個情節聲明循環幾個對函數情節。聲明的順序很重要,因爲它會按正確的順序創建透支。優雅的方式來循環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)中創建了一些頁面。我也認爲多插槽也很麻煩。也許有一種我忽略的優雅語法?

+0

這個問題仍然相關嗎?你能提供一個你的輸入的例子嗎? (我可能會花更多時間嘗試創建一個,而不是提出答案)。 – Schorsch 2013-06-05 17:01:02

+0

@Schorsch,請取消我上面MWE中的各種註釋塊,以解決問題所在。 我的MWE產生的數據直至您可以使用的'unset data'語句。 '##這工作,但很麻煩' 是產生我喜歡的輸出塊,但我不喜歡編碼。 '##這給出了一個錯誤消息' 是我想如何做事,因爲它更系統。 這可能只是在gnuplot的未來版本中才會起作用,但我想問一下現在是否有辦法做類似的事情(即明確地控制循環中的透支順序)。 – Andreas 2013-06-05 17:56:26

回答

2

而不是有兩個命令,一個用於行和一個用於點,我會建議一個命令爲帶點的線,但是 - 因爲有許多數據點 - 跳過一些情節(如同你打算用skip變量)。
基於數據集,我用下面的代碼來生成劇情:

plot [-2:2] for [ii=0:num] datfile index ii u ($1+xspeed*ii):($2-yspeed*ii) \ 
    not w lp lt ii lw 8 pt 7 pi skip ps 4 

我用w lp命令(這是短爲with linespoints)到具有線點,以及pi skip(其是pointinterval skip的縮寫)跳過符號之間的40數據點。有關linespointspointinterval的更多信息可在documentation中找到。

+0

謝謝我沒有意識到這個選項的linepoints!我一直在尋找一種通用的方式來控制繪圖順序,例如包括柵欄圖,所以我隱瞞了「接受」或現在。但我投票「有用」。 – Andreas 2013-06-13 21:12:20

+0

@AnMarkm我幾乎預料到你想要的不僅僅是帶點的線。我讚賞最後的投票。 – Schorsch 2013-06-13 21:17:09