【发布时间】:2016-10-14 09:01:12
【问题描述】:
我有一个时间相关的矩阵,我想将演变绘制为动画。
我的代码如下:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
n_frames = 3 #Numero de ficheros que hemos generado
data = np.empty(n_frames, dtype=object) #Almacena los datos
#Leer todos los datos
for k in range(n_frames):
data[k] = np.loadtxt("frame"+str(k))
fig = plt.figure()
plot =plt.matshow(data[0])
def init():
plot.set_data(data[0])
return plot
def update(j):
plot.set_data(data[j])
return [plot]
anim = FuncAnimation(fig, update, init_func = init, frames=n_frames, interval = 30, blit=True)
plt.show()
但是,当我运行它时,我总是收到以下错误:draw_artist can only be used after an initial draw which caches the render。我不知道这个错误来自哪里,也不知道如何解决它。
我已经阅读了this answer 和this article,但仍然不知道为什么我的代码不起作用。
感谢您的帮助,谢谢!
【问题讨论】:
标签: python animation matplotlib