A Tutorial for Creating Movies from Graphs of Data
This tutorial briefly demonstrates tools for making movies of graphed
data, as might be needed to show how data change with time. Before
getting into details, it will help to have an example of a completed
Below is an example of one of the images that made up a single frame of
the above movie (the 21st frame, to be exact):
The Python script that produced the movie and its constituent frames:
To create movies from graphed data as in this tutorial, you will need the
following software, all of which are open source projects available for
many different hardware platforms and operating systems:
Each of these pieces of software is useful for much more beyond what is
described in this tutorial; learning any of them in detail is worth the
effort. Fortunately, they are all well-documented. At the time of this
writing, MPlayer was the most difficult to install (compile from source),
but the instructions included with the download tell you everything you
need to know.
A general purpose programming language available at http://www.python.org. In this tutorial,
Python is used to coordinate all the steps in creating movies of graphs.
This Python package, available at http://matplotlib.sourceforge.net,
replicates much of the 2D graphing functionality and feel of the popular
Matlab software. matplotlib uses the numarray Python package to
efficiently handle large arrays of data. In this tutorial, mplotlib is
used to create graphs of data and then save the graphs as images.
A movie encoder included as part of MPlayer, available at http://www.mplayerhq.hu. MPlayer and
MEncoder can be used to create, edit and play almost any kind of movie
format, including MPGs, AVIs, MOVs, DVDs and VCDs, to name a few. In this
tutorial, MEncoder is used to stitch together images into a movie.
GraphMovieDemo.py. This is the Python
script essentially performs three tasks. First, it creates some data to
use as an example. The arrays
y store the
data. The array
x is a 1-by-1000 array of equally
spaced 64-bit floating point numbers that represent the the x-axis. The
y is a 100-by-1000 array. Each of the 100 rows of
y represent a snapshot of a function at a point in time.
Once these arrays have been created, the script goes on to plot each row
y as a function of
x. Each of the these
graphs is saved as a separate image in the directory the script is
located. Finally, the script calls upon MEncoder to piece all the images
in the directory together into an AVI movie called
output.avi. More detailed comments as to what the script is
doing are included in the script itself.
Thanks to James McBride for help with MEncoder.
This tutorial was created on 2004 August 15.