Skip to content

Instantly share code, notes, and snippets.

@vaclavcadek
Created June 30, 2017 13:06
Show Gist options
  • Save vaclavcadek/66c9c61a1fac30150514a665c4bcb5dc to your computer and use it in GitHub Desktop.
Save vaclavcadek/66c9c61a1fac30150514a665c4bcb5dc 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()
@sizhky
Copy link

sizhky commented Jan 13, 2019

Is there a way to embed this in notebook?

@David-Herman
Copy link

David-Herman commented Aug 6, 2019

I got this code working in a notebook using a markdown cell with the following code,

![SegmentLocal](colour_rotation.gif "colour_rotation")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment