'的意外行为;每';gnuplot关键字内部';代办';环

'的意外行为;每';gnuplot关键字内部';代办';环,gnuplot,Gnuplot,与循环外的行为相比,'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 1

与循环外的行为相比,
'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”。 具有循环但没有“replot”的建议版本


我含糊其辞,毫无帮助。当循环被replot的两个调用替换时,我得到了所需的输出。第一次呼叫为“每1:1:1:0:1:0”,第二次呼叫为“每1:1:2:0:2:0”。对于k=1,2,循环具有“每隔1:1:k:0:k:0”。因此,循环在逻辑上应该产生相同的输出,但它不会。我需要循环,因为真实数据集很长。请显示完整的脚本。在上面显示的片段中,“replot”没有任何意义。我们已经用完整的脚本替换了这个片段,正如我所说的,您不希望“replot”在这个循环中。每个“replot”都会重新执行上一个plot命令并添加新内容。在第二次循环中,k=2,正在执行的完整命令是“plot”every_test.dat“every 1:1:0:0:3:0 u 1:2 with points linestyle 1”,“every 1:1:k:0:k:0:0:0:0:4:5:6 with vectors filled head linestyle 1”,“every 1:1:k:0:k:0 u 3:4:5:6 with vectors filled head linestyle 1`。第一个子句来自原始绘图,第二个子句由第一个循环迭代添加,第三个子句由第二个循环迭代添加。[续][续]第2和第3条都提到k,目前k为2,因此它们都绘制了相同的内容。循环可由单个绘图命令替换,该命令每1:1:kmin:0:kmax带有向量
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
}