Help us understand the problem. What is going on with this article?

Jupyter上でmatplotlibのアニメーションを再生する

More than 3 years have passed since last update.

デモ

demo_nb.gif

方法

%matplotlib nbagg

を加えることで、matplotlibのnbaggが有効になり、Jupyter上でアニメーションが再生できます。

matplotlibの公式の説明によると、nbaggはmatplotlib 1.4で新たに追加された機能で、Jupyter上でのインタラクティブな画像表示を実現するための機能だそうです。

以下はデモのソースコードです。

demo.py
%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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away