Do an animation in 1 command in gnuplot

谁说我不能喝 提交于 2019-12-25 02:57:55

问题


I'm trying to show an animation using gnuplot I got the following script:

plot   ”heat1d.txt ”  using   1:2   every   :::a::a 
pause   0.01
a=a+1
if ( a<b )   reread

that I execute using

a = 0
b = 100
load "a.plot"

it works, but is there a way to execute all of this using only 1 command from a shell? Alternatively is there a way to integrate the variable definitions into the .plot file so that I can simply execute it? I tried different things like echo 'a=0'|gnuplot etc but it doesn't seem to actually define the variable correctly

thanks


回答1:


You can use a do for loop.

do for [a = 0:100] {
  plot   ”heat1d.txt ”  using   1:2   every   :::a::a 
  pause   0.01
}

The default terminal on linux is usually wxt, and it has the raise option, which will change the focus to the plot window at every iteration. This will make it difficult if not impossible to stop the animation.

I suggest to put noraise as the terminal option. For example, you can put the following line at the beginning of the script:

set term wxt noraise

Now, if you want to stop the animation halfway, press CtrlC on the gnuplot terminal.




回答2:


You can pass -e as a commandline argument. For example, if you have the script:

#script test.gp
print foo,bar

Then you could run it with gnuplot using:

gnuplot -e "foo=1;bar=2" test.gp

In your case, it looks like you could accomplish nearly what you want by invoking your script as:

gnuplot -e "a=0;b=100" a.plot


来源:https://stackoverflow.com/questions/14792823/do-an-animation-in-1-command-in-gnuplot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!