This is how you do it:
set terminal gif animate delay 10
The delay 10 means 10*0.01 seconds between each image. Then, you just plot each subsequent image until your done. I normally write a bash script to do this sort of thing automatically, so here’s an example.
#!/bin/bash
MAX=100
echo "clear" > plot.gpi
echo "reset" >> plot.gpi
echo "set terminal gif animate delay 10" >> plot.gpi
echo "set output \"animate.gif\"" >> plot.gpi
echo "set isosample 40" >> plot.gpi
echo "set hidden3d" >> plot.gpi
for i in `seq 0 ${MAX}`
do
echo "splot sin(${i}*x/${MAX})*cos(${i}*y/${MAX})" \
>> plot.gpi
done
So what I’m doing here is letting a bash script create a gnuplot script for me. Instead of writing out about a hundred different splots by hand, I let a for loop do that for me. Additionally, I specify a few things at the beginning.
So, put that code in a file somwhere.
Make it executable:chmod +x file
Then run it: ./file
Now, you should have a file plot.gpi that contains all the gnuplot commands.
Now open gnuplot: gnuplot
Then run the plot.gpi script: gnuplot> load 'plot.gpi'
And now you should have an animated gif creatively titled animation.gif.
When I do this in real life, I normally have a data file (perhaps generated with octave/matlab) with each time step separated by two blank lines. After two blank lines, gnuplot says we are on a new index so I can make my repeated plot line as something like:
for i ...; do echo "plot 'datafile' using 1:2 index ${i} with lines"; done
etc…
June 11, 2009 at 5:00 am |
It’s great!.
Thanks
August 2, 2010 at 7:47 pm |
echo “set output animate.gif” >> plot.gpi Here is a mistake
echo “set output \”animate.gi\”f” >> plot.gpi shuld be written
August 2, 2010 at 7:48 pm |
echo “set output \”animate.gif\” ” >> plot.gpi Sorry my mistake
December 1, 2010 at 12:19 pm |
Thanks. No other “how to” i found was as helpful as yours.
April 20, 2011 at 1:34 pm |
Thanks Gregor!
August 31, 2011 at 2:49 pm |
Very helpful, thanks! For my needs just enough.
However, I got an error when running “load ‘plot.gpi'” in gnuplot using my mac:
“Could not find/open font when opening font “Arial”, using internal non-scalable font”
+ Preview can’t open the resulting gif…
June 4, 2012 at 11:28 am |
thanks a lot. very helpful
August 31, 2012 at 2:36 pm |
thx a lot! gnuplot index made my day :)
December 13, 2012 at 7:17 pm |
Thanks a lot!
How can I speed up the animation? the “delay” command does not seem to change anything…