デモ
方法
%matplotlib nbagg
を加えることで、matplotlibの__nbagg__が有効になり、Jupyter上でアニメーションが再生できます。
matplotlibの公式の説明によると、__nbagg__はmatplotlib 1.4で新たに追加された機能で、Jupyter上でのインタラクティブな画像表示を実現するための機能だそうです。
以下はデモのソースコードです。
%matplotlib nbagg
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
x = np.arange(0, 10, 0.1)
ims = []
for a in range(50):
y = np.sin(x - a)
im = plt.plot(x, y, "r")
ims.append(im)
ani = animation.ArtistAnimation(fig, ims)
plt.show()
参考
Matplotlib animation not working in IPython Notebook (blank plot) - Stack Overflow
http://stackoverflow.com/questions/25333732/matplotlib-animation-not-working-in-ipython-notebook-blank-plot
What’s new in matplotlib — Matplotlib 1.5.1 documentation
http://matplotlib.org/users/whats_new.html#the-nbagg-backend
Pythonで簡単なアニメーションを描いてみる - Qiita
http://qiita.com/Tatejimaru137/items/3fdcc38cf8247b7056aa