I wrote a sample to animate multiple shapes with matplotlib. If you do not draw the shape you want to move before the animation, an error will occur.
#!/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)
#Draw the initial state before animating
x = np.arange(0, 10, 0.1)
y = np.sin(x)
sin01, = ax.plot(y, 'b')
sin02, = ax.plot(y, 'g')
#Frame update
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()
Recommended Posts