LoginSignup
86
66

More than 5 years have passed since last update.

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

Posted at

デモ

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

86
66
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
86
66