Этот код покажет анимацию с интервалом 1000 мс.
from scipy.spatial import ConvexHull
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
import matplotlib.animation as animation
data = {'X':[-1000, -1000, 1000, 1000, -2000, -2000, 0, 0, -3000, -3000, -1000, -1000],
'Y':[-1000, 1000, 1000, -1000, -1000, 1000, 1000, -1000, -1000, 1000, 1000, -1000],
'Time':[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]}
df = pd.DataFrame(data)
fig = plt.figure()
def animate(i):
plt.clf()
plt.xlim(-3500,3500)
plt.ylim(-3000,3000)
pts = df[df.Time == i].iloc[:, :2].values
plt.scatter(df[df.Time == i].X, df[df.Time == i].Y)
hull = ConvexHull(pts)
plt.fill(pts[hull.vertices,0], pts[hull.vertices,1],'red',alpha=0.5)
return
myAnimation = animation.FuncAnimation(fig, animate, frames=np.arange(1,4,1), interval=1000)
plt.show()
И если вы используете imagemagick, вы можете сохранить gif следующим образом.
# save animation at 30 frames per second
myAnimation.save('myAnimation.gif', writer='imagemagick', fps=30)
(на самом деле этот код в основном из здесь )