给定以下数据文件datafile.txt
"distance bus1 bicycle1"
12.1 16.29994171768731
15.0 23.23394929838676
20.0 17.63884633415712
25.0 2.2977170652861667
30.0 22.638830796409298
35.0 37.904820273943606
38.2 49.68696609775994
"distance bus1 bicycle2"
12.1 10.389230000341742
15.0 15.82783623872837
20.0 11.262011365648817
25.0 2.3291889288592533
30.0 25.930554010842158
35.0 45.36376748022544
38.2 57.535263969151465
此命令有效。
plot for [i=0:1] 'datafile.txt' index i with lines title columnheader(1), 1.0 with lines title "collision limit"
这个命令也有效。
plot for [i=0:*] 'datafile.txt' index i with lines title columnheader(1)
但是组合 * 和逗号会在 gnuplot 中产生语法错误:
plot for [i=0:*] 'datafile.txt' index i with lines title columnheader(1), 1.0 with lines title "collision limit"
gnuplot> plot for [i=0:*] 'datafile.txt' index i with lines title columnheader(1), 1.0 with lines title
"collisio
^
warning: ignoring trailing comma in plot command
gnuplot> plot for [i=0:*] 'datafile.txt' index i with lines title columnheader(1), 1.0 with lines title
"collisio"
^
unexpected or unrecognized token
gnuplot> n limit"
gnuplot> plot for [i=0:*]
^
function to plot expected
你知道我做错了什么吗?我正在使用 gnuplot 5.2 patchlevel 7。
最佳答案
使用*
进行循环,例如plot for [i=0:*] ...
也会在其他场合引起问题(至少我经历过)。然而,另一种解决方法如下,但代价是 stats
进行一些额外的计算。然后您可以使用变量STATS_blocks
,它应该告诉您数据集的数量,即最大索引等于STATS_blocks-1
:
FILE = 'datafile.txt'
stats FILE nooutput
plot for [i=0:STATS_blocks-1] FILE index i with lines title columnheader(1), \
1.0 with lines title "collision limit"
关于gnuplot - 语法错误 : several plots, 其中之一是带有星号(星号)模式的 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58063778/