matplotlibで複数の図形をアニメーションさせるサンプルを書きました。
アニメーション前に動かしたい図形を描画しておかないとエラーが出ます。
サンプルコード
#!/usr/local/bin/python3.5
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure(1)
ax = fig.add_subplot(111)
#アニメーションさせる前に初期状態を描いておく
x = np.arange(0, 10, 0.1)
y = np.sin(x)
sin01, = ax.plot(y, 'b')
sin02, = ax.plot(y, 'g')
#フレーム更新
def update(i):
sin01.set_ydata(np.sin(x-i))
sin02.set_ydata(np.sin(x+i))
ani = animation.FuncAnimation(fig, update, 1000, blit=False, interval=100, repeat=False)
#ani.save('./animation.mp4')
plt.show()