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

前端 未结 4 903
慢半拍i
慢半拍i 2020-12-05 00:19

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



        
相关标签:
4条回答
  • 2020-12-05 00:38

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

    import matplotlib
    matplotlib.use('TkAgg')
    
    0 讨论(0)
  • 2020-12-05 00:55

    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)
    
    0 讨论(0)
  • 2020-12-05 00:57

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

    0 讨论(0)
  • 2020-12-05 01:00

    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)
    
    0 讨论(0)
提交回复
热议问题