animation - Can't get my program to animate multiple patches in python matplotlib -


i attempting animate 2 different particles in matplotlib (python). figured out way animate 1 particle in matplotlib, havign difficulties trying program work multiple particles. know wrong , how fix it?

import numpy np matplotlib import pyplot plt matplotlib import animation  fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(5, 4.5)  ax = plt.axes(xlim=(0, 100), ylim=(0, 100)) enemy = plt.circle((10, -10), 0.75, fc='r') agent = plt.circle((10, -10), 0.75, fc='b')    def init():     #enemy.center = (5, 5)     #agent.center = (5, 5)     ax.add_patch(agent)     ax.add_patch(enemy)      return []  def animationmanage(i,agent,enemy):     patches = []      enemy.center = (5, 5)     agent.center = (5, 5)      enemy_patches = animatecos(i,agent)     agent_patches = animateline(i,enemy)      patches[enemy_patches, agent_patches]      #patches.append(ax.add_patch(enemy_patches))     #patches.append(ax.add_patch(agent_patches))      return enemy_patches  def animatecirc(i, patch):     # seems represents time step     x, y = patch.center     # 1st constant = position , 2nd constant = trajectory     x = 50 + 30 * np.sin(np.radians(i))     y = 50 + 30 * np.cos(np.radians(i))     patch.center = (x, y)     return patch,  def animateline(i, patch):     x, y = patch.center     x = x + 1     y = x+ 1     patch.center = (x, y)     return patch,   def animatecos(i, patch):     x, y = patch.center     x = x + 0.2     y = 50 + 30 * np.cos(np.radians(i))     patch.center = (x, y)     return patch,  def animatesin(i, patch):     x, y = patch.center     x = x + 0.2     y = 50 + 30 * np.sin(np.radians(i))     patch.center = (x, y)     return patch,   anim = animation.funcanimation(fig, animationmanage,                                 init_func=init,                                 frames=360,                                fargs=(agent,enemy,),                                interval=20,                                blit=true)   plt.show() 

working code animating 1 particle

import numpy np  matplotlib import pyplot plt matplotlib import animation  fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(5, 4.5)  ax = plt.axes(xlim=(0, 100), ylim=(0, 100)) enemy = plt.circle((10, -10), 0.75, fc='r') agent = plt.circle((10, -10), 0.75, fc='b')  def init():     enemy.center = (5, 5)     agent.center = (5, 5)     ax.add_patch(enemy)     ax.add_patch(agent)     return enemy,  def animatecirc(i, patch):     # seems represents time step     x, y = patch.center     # 1st constant = position , 2nd constant = trajectory     x = 50 + 30 * np.sin(np.radians(i))     y = 50 + 30 * np.cos(np.radians(i))     patch.center = (x, y)     return patch,  def animateline(i, patch):     x, y = patch.center     x = x + 1     y = x+ 1     patch.center = (x, y)     return patch,   def animatecos(i, patch):     x, y = patch.center     x = x + 0.2     y = 50 + 30 * np.cos(np.radians(i))     patch.center = (x, y)     return patch,  def animatesin(i, patch):     x, y = patch.center     x = x + 0.2     y = 50 + 30 * np.sin(np.radians(i))     patch.center = (x, y)     return patch,   anim = animation.funcanimation(fig, animatecos,                                 init_func=init,                                 frames=360,                                fargs=(enemy,),                                interval=20,                                blit=true)  plt.show() 

import numpy np matplotlib import pyplot plt matplotlib import animation  fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(5, 4.5)  ax = plt.axes(xlim=(0, 100), ylim=(0, 100)) enemy = plt.circle((10, -10), 0.75, fc='r') agent = plt.circle((10, -10), 0.75, fc='b')   def init():     enemy.center = (5, 5)     agent.center = (5, 5)     ax.add_patch(agent)     ax.add_patch(enemy)      return []   def animationmanage(i,agent,enemy):     animatecos(i,enemy)     animateline(i,agent)     return []   def animateline(i, patch):     x, y = patch.center     x += 0.25     y += 0.25     patch.center = (x, y)     return patch,   def animatecos(i, patch):     x, y = patch.center     x += 0.2     y = 50 + 30 * np.cos(np.radians(i))     patch.center = (x, y)     return patch,  anim = animation.funcanimation(fig, animationmanage,                                init_func=init,                                frames=360,                                fargs=(agent,enemy,),                                interval=20,                                blit=true,                                repeat=true)   plt.show() 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -