Skip to content

Instantly share code, notes, and snippets.

@Akramz
Forked from vaclavcadek/generate_gif.py
Created February 11, 2019 19:33
Show Gist options
  • Save Akramz/201613866c28695dc88e04419dca99fa to your computer and use it in GitHub Desktop.
Save Akramz/201613866c28695dc88e04419dca99fa to your computer and use it in GitHub Desktop.
How to generate animation using numpy arrays.
from matplotlib.animation import FuncAnimation
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(5, 8))
def update(i):
im_normed = np.random.random((64, 64))
ax.imshow(im_normed)
ax.set_title("Angle: {}*pi/10".format(i), fontsize=20)
ax.set_axis_off()
anim = FuncAnimation(fig, update, frames=np.arange(0, 20), interval=50)
anim.save('colour_rotation.gif', dpi=80, writer='imagemagick')
plt.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment