我已经创造了一些动画后就正常了 - 尽管 - 缓凝时关键字:matplotlib动画块传输=真正原因KeyError异常
blit=False
然而,在我的努力通过设定块传输,以加快动画=真我在运行我的测试时遇到了一些奇怪的KeyError异常。
最后,我有一个预感,它可能不会有一个编码错误,但也许有一个设置,甚至一个错误。
因此我从here导入了simple_anim.py脚本,发现发生了同样的错误。
我测试过一些例子,他们都给出了相同的异常.... :(
任何人可以帮助我,并给上发生了什么事情的一些信息?
的代码是以下:
"""
A simple example of an animated plot
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01)
line, = ax.plot(x, np.sin(x))
def animate(i):
line.set_ydata(np.sin(x + i/10.0)) # update the data
return line,
# Init only required for blitting to give a clean slate.
def init():
line.set_ydata(np.ma.array(x, mask=True))
return line,
ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init,
interval=25, blit=True)
plt.show()
凸起的例外是:
Traceback (most recent call last):
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 1305, in _on_timer
ret = func(*args, **kwargs)
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py", line 1021, in _step
still_going = Animation._step(self, *args)
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py", line 827, in _step
self._draw_next_frame(framedata, self._blit)
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py", line 845, in _draw_next_frame
self._pre_draw(framedata, blit)
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py", line 858, in _pre_draw
self._blit_clear(self._drawn_artists, self._blit_cache)
File "/home/dj754/anaconda3/lib/python3.5/site-packages/matplotlib/animation.py", line 898, in _blit_clear
a.figure.canvas.restore_region(bg_cache[a])
KeyError: <matplotlib.axes._subplots.AxesSubplot object at 0x7fb3b9d3a198>
我只有'interval'低于'60'的问题 - 我的错误表明问题始于用于显示窗口的Tkinter。当然,程序启动两个线程(或者更确切的说,使用Tkinter'after()'后周期性地执行'animate()',一些元素的启动速度会比其他元素快,然后是第一个元素所需的其他元素 – furas
当我在家运行这个代码时 - 认为是 - 相同的软件配置:一切正常但是... 我已经能够重新创建相同的KeyError的东西,当我插入一个'plt.show()'语句之前创建动画与'FuncAnimation ....)'电话 ...我有一种感觉,我正在进行一些事情。 –
..经过一番进一步的调查,我发现在代码的开头添加'plt.ion()'语句会导致它给出这个'KeyError'异常,**只有当'blit = True'被设置。当我将其更改为'blit = False'时,它仍然工作。 不幸的是,我无法在工作中测试我的代码(根据我提出的这个问题),但我很快就会做到这一点。 –