Ich habe ein Beispiel geschrieben, um mehrere Figuren mit matplotlib zu animieren. Wenn Sie die Form, die Sie verschieben möchten, vor der Animation nicht zeichnen, wird eine Fehlermeldung angezeigt.
#!/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)
#Zeichnen Sie den Ausgangszustand vor dem Animieren
x = np.arange(0, 10, 0.1)
y = np.sin(x)
sin01, = ax.plot(y, 'b')
sin02, = ax.plot(y, 'g')
#Rahmenaktualisierung
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