2013-05-10 176 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