在我的Mac OSX机器上浏览matplotlib的动画示例 - http://matplotlib.org/examples/animation/simple_anim.html - 我收到此错误: -
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'
之前遇到此问题的人是否知道如何解决此问题?
看起来这是一个已知的(在撰写本文时尚未解决)问题 - https://github.com/matplotlib/matplotlib/issues/531
答案 0 :(得分:47)
只需设置
blit=False
调用animation.FuncAnimation()时它会起作用。
例如(from double_pendulum_animated):
ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)), interval=25, blit=False, init_func=init)
答案 1 :(得分:21)
您可以通过切换到其他后端来避免此问题:
import matplotlib
matplotlib.use('TkAgg')
答案 2 :(得分:5)
如https://mail.python.org/pipermail/pythonmac-sig/2012-September/023664.html所述:
>>> longest_subsequence([3,5,6,2,5,4,19,5,6,7,12])
[3, 4, 5, 6, 7, 12]
对于我来说,在OSX 10.11.6,Python 2.71上使用ActiveState Tkinter安装安装Tkinter对我有用。 基本动画示例仍然有点嘈杂,直到line_ani代码中的blt = False:
import matplotlib
matplotlib.use('TkAgg')
#just *before*
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
答案 3 :(得分:2)
看起来这是一个已知的(在撰写本文时尚未解决)问题 - https://github.com/matplotlib/matplotlib/issues/531