Skip to content
/ pltmov Public

Pyplot to FFmpeg wrapper for easy animation of plots and figures

Notifications You must be signed in to change notification settings

oiao/pltmov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package provides a wrapper around ffmpeg, allowing for fast conversion of your pyplot plots into a movie file.

Installation

  • git clone https://github.com/oiao/pltmov.git
  • pip install -e pltmov

How to use

1. Import and initialize a Movie instance

from pltmov import Movie
movie = Movie()

2. Define your plotting function as usual, but use the instance's record decorator

import numpy as np
import matplotlib.pyplot as plt

@movie.record
def plot(xmax, text):
    x = np.linspace(0, xmax, int(np.sqrt(xmax)*100))
    plt.plot(x, np.sin(x))
    plt.text(0.1, 0.1, str(text), transform=plt.gca().transAxes, size=18)
    plt.tight_layout()

Make sure that:

  • your plotting function does not save anything to disk
  • there are no keyword arguments in the function

3. Each call to the plotting function is now recorded as a frame in your movie

ranges = np.linspace(0.1,  100, 1000) # 1k frames
texts  = [f"frame {i}" for i in range(1, len(ranges)+1)]
for r, t in zip(ranges,texts):
    plot(r, t)

4. Save your movie

movie.write('movie.mp4', fps=60)

All arguments for write() are documented in the docstring.

About

Pyplot to FFmpeg wrapper for easy animation of plots and figures

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published