Created
December 16, 2015 12:14
-
-
Save ebothmann/79470abe4b90606ee6c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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