Skip to content

Instantly share code, notes, and snippets.

@ebothmann
Created December 16, 2015 12:14
Show Gist options
  • Select an option

  • Save ebothmann/79470abe4b90606ee6c0 to your computer and use it in GitHub Desktop.

Select an option

Save ebothmann/79470abe4b90606ee6c0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
# what to plot
def y(x, t):
return np.sin(x - t)
# where to plot
fps = 60
frames = 2*60
x = np.linspace(0, 2*np.pi)
t = np.linspace(0, 2*np.pi, frames)
# how to plot
fig = plt.figure()
line = plt.plot(x, y(x, 0))[0]
plt.xlim(0, 2*np.pi)
# perform animation
ani = animation.FuncAnimation(fig,
lambda i: line.set_data(x, y(x, t[i])),
frames=frames, repeat=True)
ani.save('simple_animation.mp4', fps=fps, extra_args=['-vcodec', 'libx264'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment