36

Walking through matplotlib's animation example on my Mac OSX machine - http://matplotlib.org/examples/animation/simple_anim.html - I am getting this error:-

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/animation.py", line 248, in _blit_clear
    a.figure.canvas.restore_region(bg_cache[a])
AttributeError: 'FigureCanvasMac' object has no attribute 'restore_region'

Does anyone who has encountered this before know how to resolve this issue?

Looks like it's a known (and unresolved at this time of writing) issue - https://github.com/matplotlib/matplotlib/issues/531

4

4 回答 4

47

刚设置

blit=False

animation.FuncAnimation()被调用并且它会工作。

例如(来自 double_pendulum_animated):

ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)), interval=25, blit=False, init_func=init)
于 2013-09-12T14:43:47.900 回答
25

您可以通过切换到不同的后端来避免该问题:

import matplotlib
matplotlib.use('TkAgg')
于 2013-07-07T16:22:32.503 回答
5

https://mail.python.org/pipermail/pythonmac-sig/2012-September/023664.html所述,使用:

import matplotlib
matplotlib.use('TkAgg')

#just *before*

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

使用 OSX 10.11.6、Python 2.71 上的 ActiveState Tkinter 安装安装 Tkinter 时,这对我有用。基本动画示例仍然有点嘈杂,直到此处的 line_ani 代码中的 blt=False:

line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
interval=50, blit=False)
于 2016-10-12T08:03:11.297 回答
2

看起来这是一个已知(在撰写本文时尚未解决)问题 - https://github.com/matplotlib/matplotlib/issues/531

于 2013-01-18T00:20:14.317 回答