I found the following thread in the physics stackexchange where I saw the video called output attached to the main post. The video can be found here.

How would I go about creating such an animation?


5 Answers 5


In case you are interested in generating the individual frames, here is a little example in python:

import matplotlib
import matplotlib.pyplot as plt   # For plotting graphs.
import numpy as np
import subprocess                 # For issuing commands to the OS.
import os
import sys                        # For determining the Python version.
import glob

fileList = glob.glob(os.path.join("LEMtrace*.dat"))

style = {0: '--',
         1: '-',
         2: '-.',
         3: ':'}
color = {0: 'k',
         1: 'r',
         2: 'g',
         3: 'b'}
n = 0
for f in fileList:
    n = n + 1
    data = np.loadtxt(f)
    ax = plt.subplot(111)
    ax.set_xlabel('LEM cell')
    ax.set_ylabel('Mass fraction or T / 2000 K')
    str = 'Time {0:.5f} ms'.format(n * 5.8e-5)
    leg = ax.legend(loc='best', shadow=True, fancybox=True)
    fig = "frame_%04d"%(n)

command = ('mencoder',
print "\n\nabout to execute:\n%s\n\n" % ' '.join(command)
command = ('convert',

print "\n\n The movie was written to 'output.avi'"

Assuming you have some 1D data stored in the LEMtrace*.dat files, this program loads the data for each file using numpy.loadtxt (great for text files), plots a simple graph using matplotlib and output 1 frame for each file with nice little time counter. Then it uses either mencoder or convert to generate an avi or gif animation. Hope this helps !

PS: A not so pretty (because of the data) example of the output: GIFsample


I will assume that you know how to output all the frames you want in the movie. Then a simple free tool to turn them into a movie as Imagemagick's convert. If you are on a Linux system, you probably already have it or can easily get it through your package manager. Depending on the format of movie you want to make, you will also need an appropriate encoder (e.g., ffmpeg). If you have a bunch of files


Then you simply

convert *.png movie.mpg

There are lots of options you can use to change the framerate and other things; see the documentation for convert linked above.


I use Mathematica a lot for this kind of things... Animation can be made very easily:

  Plot[Sin[x + t] + Cos[0.3 x + t], {x, 0, 20},PlotRange -> {All, {-2, 2}}],
  {t, 1, 10}

This gives you an interactive plot with a slider to drag for t.

To save the animation as a movie just export it:

  Table[Plot[Sin[x + t] + Cos[0.3 x + t], {x, 0, 20}, PlotRange -> {All, {-2, 2}}], 
    {t, 1, 10, 0.1}


moving wave


There is also a freeware program ffmpeg which is freely available. If you prefer to have a GUI to do it, you may also want to consider using ImageJ.


For quick viz nothing beats gnuplot ...

for i in `seq 1 100`; do echo "set pm3d; set zrange [1:5000]; splot $i*x**2+$i*y**2"; done | gnuplot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.