Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac OSX - AttributeError: 'FigureCanvasMac' object has no attribute 'restore_region'

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

like image 602
Calvin Cheng Avatar asked Nov 04 '12 06:11

Calvin Cheng


3 Answers

Just set

blit=False

when animation.FuncAnimation() is called and it will work.

For instance (from double_pendulum_animated):

ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)), interval=25, blit=False, init_func=init)
like image 63
jw1123 Avatar answered Nov 13 '22 03:11

jw1123


You can avoid the problem by switching to a different backend:

import matplotlib
matplotlib.use('TkAgg')
like image 24
Beau Avatar answered Nov 13 '22 05:11

Beau


As noted at https://mail.python.org/pipermail/pythonmac-sig/2012-September/023664.html use:

import matplotlib
matplotlib.use('TkAgg')

#just *before*

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

This has worked for me with Tkinter installed using the ActiveState Tkinter installation on OSX 10.11.6, Python 2.71 The basic animation example is still a little noisy until blt=False in the line_ani code here:

line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
interval=50, blit=False)
like image 5
ReaddyEddy Avatar answered Nov 13 '22 04:11

ReaddyEddy