我想使用 Gnuplot 生成几个图,这就是我需要使用循环的原因。数据从文件“sort'i'.dat”加载。代码如下所示,但不起作用。我的主循环有一些问题。我不知道为什么它不起作用,也许它与我的 Gnuplot 版本有关。谢谢。
do for [i=0:10] {
set term png
set output 'sort'.i.'.png'
set title "Quick sort"
set xlabel "Position number"
set ylabel "Number on position"
unset key
plot 'sort'.i.'.dat' using 1:2 with points pt 5
}
错误是:
“第 1 行:无效的复数常量”
这种do for
4.6.0版本引入了迭代:
以下迭代仅从 4.6.0 开始有效:
do for [i=0:10] { print i }
迭代
plot for [i=0:10] i*x
也适用于 4.4
4.4 的另一种选择虽然相当丑陋,但却是“外包”迭代。只有两条线依赖于迭代变量,这使得这是可行的。您在 gnuplot 之外构建所有绘图指令,然后eval
完整的字符串:
以使用 bash 为例:
set terminal pngcairo
set title "Quick sort"
set xlabel "Position number"
set ylabel "Number on position"
unset key
set style data points
loopstr = 'set output ''sort%d.png''; plot ''sort%d.dat'' using 1:2 pt 5; '
eval(system('exec bash -c "for ((a=0;a<=10;a++)) do printf \"'.loopstr.'\" \$a \$a; done" '))
For the exec bash
see gnuplot 和 bash 进程替换 https://stackoverflow.com/a/19290463/2604213。当然,您可以使用任何其他程序来进行迭代。
但这当然并不能取代 gnuplot 内部迭代的便利性。为什么不升级到4.6?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)