Неожиданное поведение каждого ключевого слова gnuplot внутри цикла do for - PullRequest
0 голосов
/ 30 мая 2019

Неожиданное поведение '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

1 Ответ

1 голос
/ 30 мая 2019

Я подозреваю, что проблема заключается в использовании вами "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
}
...