This package provides a wrapper around ffmpeg, allowing for fast conversion of your pyplot plots into a movie file.
git clone https://github.com/oiao/pltmov.git
pip install -e pltmov
from pltmov import Movie
movie = Movie()
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
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)
movie.write('movie.mp4', fps=60)
All arguments for write()
are documented in the docstring.