循环'every' gnuplot 关键字'do for'意外行为


循环

'every'的意外行为与循环外的行为相比'do for'

set style line 1 linecolor rgb "blue" pointtype 7 pointsize 3 lt 1
#plot 4 points
plot 'every_test.txt' every 1:1:0:0:3:0 u 1:2 with points linestyle 1 
# Next 4 lines, when active, draw 2 arrows from 2nd point to 1st & 3rd 
#pause 1
#replot '' every 1:1:1:0:1:0 u 3:4:5:6 with vectors filled head linestyle 1
#pause 1
#replot '' every 1:1:2:0:2:0 u 3:4:5:6 with vectors filled head linestyle 1
# Try 'do for' loop instead of preceding 4 line to draw the 2 arrows
do for [k = 1:2] {
   pause 1
   replot '' every 1:1:k:0:k:0 u 3:4:5:6 with vectors filled head linestyle 1
}
# Loop behaves unexpectedly. 
# It draws 1st arrow, removes it [how does replot even do that!] 
# then draws 2nd arrow. Final result is 2nd arrow only. 
replot '' every 1:1:1:0:1:0 u 3:4:5:6 with vectors filled head linestyle 1
# Line above attempts to restore 1st arrow, but only results in error:
# "undefined variable: k" even though it makes no reference to k.

every_test.txt中的数据:

1  2 
2  3 1.9  2.9 -0.8 -0.8
3  2 2.1  2.9  0.8 -0.8
4  1
5  3
6  4

我怀疑问题是你使用了"replot"。带有循环但没有"重绘"的建议版本

do for [k=1:N] {
    plot 'every_test.txt' every 1:1:0:0:3:0 u 1:2 with points linestyle 1, 
    '' every 1:1:1:0:k:0 u 3:4:5:6 with vectors filled head linestyle 1
    pause 1
}

最新更新