I am trying to make an animation of an expanding circle using FuncAnimation and circle.set_radius(). However, the animation only works when blit = False. The code is as follow:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
fig, ax = plt.subplots()
plt.grid(True)
plt.axis([-0.6, 0.6, -0.6, 0.6])
circle1= plt.Circle([0,0],0.01,color="0.",fill=False, clip_on = True)
ax.add_patch(circle1)
dt = 1.0/20
vel = 0.1
def init():
circle1.set_radius(0.01)
def animate(i):
global dt, vel
r = vel * i * dt
circle1.set_radius(r)
return circle1,
anim = animation.FuncAnimation(fig, animate, init_func=init,
frames=200, interval= 50, blit=True)
It returns this error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/matplotlib/artist.py", line 61, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/figure.py", line 1139, in draw
self.canvas.draw_event(renderer)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 1809, in draw_event
self.callbacks.process(s, event)
File "/usr/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 562, in process
proxy(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/cbook.py", line 429, in __call__
return mtd(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 620, in _start
self._init_draw()
File "/usr/local/lib/python2.7/site-packages/matplotlib/animation.py", line 1166, in _init_draw
for a in self._drawn_artists:
TypeError: 'NoneType' object is not utterable
I am using mac OS. The animation will work when I changed blit = False. However, whenever I move my mouse there animation slow down. This is problematic because I have a separate thread generating the sound output. In practice, the circle will hit some data points and make sound. As a result they are not in sync. Please help.