title: plotting lines in pairs
body: <p>I'm working on a network project in which I need to draw lines (edges) between pairs of points (nodes). Currently I'm using matplotlib.pyplot for this, but the problem is that pyplot.plot(x, y) starts at (x[0], y[0]) and then continues to (x[1], y[1]) etc.<br>
  I have a separate list of tuples for the connections of the nodes:<br>
  edges=[(0,1), (0,2), (3,2), (2,1)...(m,n)], which refers to indices of the separate nodes.
  The problem is that I need to animate the thing with matplotlib.animation.</p>
  
  <p>To just add lines between nodes (static picture) I was using ax.add_line(Line2D([x1, x2], [y1, y2])), but I can't figure out how to get this method to work with animation.FuncAnimation().</p>
  
  <p>Some dummy code:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  edges = [(0,1), (2,3), (3,0), (2,1)]
  
  x = [-5, 0, 5, 0]
  y = [0, 5, 0, -5]
  
  lx = []
  ly = []
  for edge in edges:
      lx.append(x[edge[0]])
      lx.append(x[edge[1]])
      ly.append(y[edge[0]])
      ly.append(y[edge[1]])
  
  plt.figure()
  plt.plot(x, y, 'ro')
  plt.plot(lx, ly, '-', color='#000000')
  plt.show()
  </code></pre>
  
  <p>(Image of this and the next example below)</p>
  
  <p>If I instead use the following:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from pylab import Line2D, gca
  
  edges = [(0,1), (2,3), (3,0), (2,1)]
  
  x = [-5, 0, 5, 0]
  y = [0, 5, 0, -5]
  
  plt.figure()
  ax = gca()
  for edge in edges:
      ax.add_line(Line2D([x[edge[0]], x[edge[1]]], [y[edge[0]], y[edge[1]]], color='#000000'))
  
  ax.plot(x, y, 'ro')
  plt.show()
  </code></pre>
  
  <p>it all works the way I need:
  <a href="http://imgur.com/U818rtM" rel="nofollow">Examples</a>.<br>
  Unfortunately, this is not possible (afaik) during animation. What I need then is is a way to plot lines between individual pairs of nodes.</p>
  
  <p>Very bad problem formulation, I know, but I hope that someone understands and is able to help.</p>
  
  <p>Thank you!</p>