

.. _sphx_glr_gallery_animation_movie_demo_sgskip.py:


==========
Movie Demo
==========




.. code-block:: python


    from __future__ import print_function

    import os
    import subprocess
    import matplotlib.pyplot as plt
    import numpy as np

    # Fixing random state for reproducibility
    np.random.seed(19680801)


    files = []

    fig, ax = plt.subplots(figsize=(5, 5))
    for i in range(50):  # 50 frames
        plt.cla()
        plt.imshow(np.random.rand(5, 5), interpolation='nearest')
        fname = '_tmp%03d.png' % i
        print('Saving frame', fname)
        plt.savefig(fname)
        files.append(fname)

    print('Making movie animation.mpg - this may take a while')
    subprocess.call("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 -ovc lavc "
                    "-lavcopts vcodec=wmv2 -oac copy -o animation.mpg", shell=True)

    # cleanup
    for fname in files:
        os.remove(fname)

**Total running time of the script:** ( 0 minutes  0.000 seconds)



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

     :download:`Download Python source code: movie_demo_sgskip.py <movie_demo_sgskip.py>`



  .. container:: sphx-glr-download

     :download:`Download Jupyter notebook: movie_demo_sgskip.ipynb <movie_demo_sgskip.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.readthedocs.io>`_
