title: Keeping animated objects from disappearing in python matplotlib animation
body: <p>I am trying to use matplotlib's animation feature to animate multiple objects. By default, the animation feature erases old instances of the object each time it calls your animation function and you change the position of the line or patch or whatever. (Of course, this is the whole point of animation). But I have 2 different objects to be animated: a line that sweeps a polar plot in azimuth, and scatter markers. I don't want the markers to disappear. I want them to persist throughout the animation once they've been drawn. </p>
  
  <p>I've tried a couple different things like appending the 'marker' scatter points to a list and returning it, but I'm having trouble with the return of the animate function. Here is the basic code without trying to append to a list. I trimmed down a lot of the figure and axis setup. As this code sits, the line sweeps around the plot and when it reaches a point where a marker is, the marker flashes then disappears.</p>
  
  <pre><code>fig = plt.figure(1)
  ax = fig.add_subplot(111,projection='polar')
  ax.set_theta_zero_location('N',offset=0)
  ax.set_theta_direction(-1)
  line, = ax.plot((0,0),(0,0))
  list = []
  def animate(i):
      line.set_data((0,line_az_time[i][0]),(0,300))
      if(line_az_time[i][1] in marker_time):
          marker = plt.scatter(marker_az[0],marker_range[0])
          list.append(marker)
          del marker_az[0]
          del marker_range[0]
          return line, list  # wrong return type?
      return line, list  # how to handle empty list before 1st marker appended?
  
  def init():
      line.set_data((0,0),(0,300))
      return line,
  
  ani = animation.FuncAnimation(fig,animate,np.arange(len(line_az_time)),
        blit=True,interval=0,repeat=True,init_func=init)
  
  plt.show()
  </code></pre>
  
  <p>'line_az_time' is a nested list of the format [[angle1, time1],[angle2,time2]...]
  Basically it saves an angle and the time that angle occurs. the 'marker_xxx' variables are the angles, ranges, and times of target detections. When the line is getting animated, it is checking if a detection is occuring at that time and angle. The times and detections are always sequential, so I just delete them once they've been plotted.</p>
  
  <p>Basically all I need is keeping the 'marker' scatter points to persist throughout the animation. As stated before, I tried appending them to a list and returning the list instead of 'marker' itself. That way, they all get plotted once they've occurred. But that didn't work. I think I am confused by what type of variable to pack them into and how to write the 'return' lines once I append them to a variable.</p>
  
  <p>Or if there is another way, I'd be open to that as well.</p>