movie_test, a Python code which creates a movie file from a sequence of solutions to a partial differential equation, using matplotlib.

matplotlib provides a procedure FuncAnimation() for creating animations. However, this procedure has limited documentation, and a peculiarly constrained user interface. The user provides a ``frame(i)'' function whose only input is the frame counter i, which must return, in a somewhat obscure fashion, the raw plot elements involved in the frame.

While it's not too hard to use this facility to create an animation of a sine curve, it's more difficult to see how to, for instance, compute a sequence of solutions to a partial differential equation, and display the sequence of time solutions in a movie file. One difficulty is that this calculation requires the frame function to have access to the data at the previous time step, which can't be done through the parameter list, and which isn't easily done simply by declaring the data in the user's main program. This code demonstrates one way of computing a scientifically interesting result and creating a movie from it.


The computer code and data files described and made available on this web page are distributed under the MIT license


movie_test is available in a Python version.

Related Data and Programs:

allen_cahn_pde, a Python code which sets up and solves the 1D Allen-Cahn reaction-diffusion partial differential equation (PDE).

animation_test, a Python code which computes a sequence of solutions to a partial differential equation, using matplotlib, displaying each solution to the screen WITHOUT requiring the user to hit RETURN to see the next image.

graphics_test, a Python code which illustrates how various kinds of data can be displayed and analyzed graphically.


Source Code:

Last revised on 24 February 2023.