'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
答案 0 :(得分:0)
我怀疑问题是您使用了“ 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
}