title: Python Script to animate a set of lines in a class
body: <p>I am trying to put the matplotlib.animation set into a class function. Though I don't seem to be having much luck. I have tried both, FunctionAnimation() &amp; ArtistAnimation(). For both I don't seem to be able to get them to work (though they are vastly different). </p>
  
  <pre><code># ------------------------------ #
  import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  # ------------------------------ #
  class AniPlot():
      def __init__(self):
          self.fig = plt.figure()
          self.ax = plt.axes(xlim=(-3.5, 3.5), ylim=(-5, 2))
          self.line, = self.ax.plot([], [], lw=2)
  
  
      def set_data(self,tvector):
          self.data = tvector
  
      def ani_init(self):
          self.line.set_data([], [])
  
      def ani_update(i):
          x = self.data[i][0]
          y = self.data[i][1]
  
          self.line.set_data(x, y)
          return self.line,
  
  
      def animate(self):
          anim = animation.FuncAnimation(self.fig, self.ani_update, init_func=self.ani_init,
                                 frames=4, interval=20, blit=True)
          plt.show()
  
  # ------------------------------ #
  
  data = [
  [[0,0,1,0],[0,-1,-2,-3]],
  [[0,0,0,0.1],[0,-1,-3,-4]],
  [[0,0,0.5,0],[0,-1,-2.5,-3.5]],
  [[0,0,1,2],[0,-1,-2,-2.5]]
          ]
  myani = AniPlot()
  myani.set_data(data)
  myani.animate()
  </code></pre>
  
  <p>I want to try get my head around it, rather than use someone else's code. Though I did use others as a starting point. Can anyone help?</p>