使用循环在Gnuplot中生成图 [英] Generating plots in Gnuplot using loops

查看:61
本文介绍了使用循环在Gnuplot中生成图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Gnuplot生成多个图,这就是为什么我需要使用循环的原因.数据是从文件"sort'i'.dat"加载的.该代码如下所示,但不起作用.我在主循环上遇到了一些问题.我不知道为什么它不起作用,也许它与我的Gnuplot版本有关.谢谢.

I would like to generate several plots using Gnuplot thats why I need to use loop. The data is loading from files "sort'i'.dat". The code is shown below but it doesn't work. I have got some problem with main loop. I don't know why it doesn't work, maybe it is connected with my version of Gnuplot. Thanks.

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行:无效的复数​​常量"

The error is: "line 1: invalid complex constant"

推荐答案

在4.6.0版本中引入了这种do for迭代:

This kind of do for iteration was introduced in version 4.6.0:

以下迭代仅从4.6.0开始有效:

The following iteration works only since 4.6.0:

do for [i=0:10] { print i }

迭代

plot for [i=0:10] i*x

也可用于4.4

4.4的另一种选择虽然很丑陋,但将外包"这些迭代.只有两行依赖于迭代变量,这使得这可行.您可以在gnuplot之外构造所有绘图指令,然后eval完整字符串:

One other option for 4.4, although quite ugly, would be to "outsource" the iterations. Only two of the lines depend on the iteration variable, which make this feasible. You construct all the plot instructions outside of gnuplot and then eval the complete string:

作为使用bash的示例:

As an example using 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" '))

有关exec bash的信息,请参见 gnuplot和bash进程替换.当然,您可以使用任何其他程序进行迭代.

For the exec bash see gnuplot and bash process substitution. Of course you can use any other program to do the iteration.

但是,这当然不能取代使用gnuplot内部迭代的简便性.为什么不升级到4.6?

But this doesn't of course replace the ease of having the gnuplot-internal iterations. Why not upgrade to 4.6?

这篇关于使用循环在Gnuplot中生成图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆