lezebulon
lezebulon

Reputation: 7994

Do an animation in 1 command in gnuplot

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

Upvotes: 0

Views: 1642

Answers (2)

syockit
syockit

Reputation: 5834

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.

Upvotes: 3

mgilson
mgilson

Reputation: 310049

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

Upvotes: 0

Related Questions