title: In python, drawing a list of line segments given their indices
body: <p>Given a list of vertices, and a list of line segments (indices which refer to the vertices of a segment), what's the best way of drawing all the lines segments where they may not form a continuous line?</p>
  
  <p>I can do it this way, but it's obviously clunky; is there a better way?</p>
  
  <pre><code>vertices=[[0,0],[1,1],[1,2],[4,1]]
  segs=[[0,1],[0,2],[2,3]] 
  
  for seg in segs:
      x = vertices[seg[0]][0], vertices[seg[1]][0]
      y = vertices[seg[0]][1], vertices[seg[1]][1]
      plot(x, y, 'k')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lz2wh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lz2wh.png" alt="This is what I get"></a></p>
  
  <p>@CactusWoman gives a way that works. This is the full code.</p>
  
  <pre><code>import matplotlib
  import matplotlib.collections
  import matplotlib.pyplot
  
  vertices=[[0,0],[1,1],[1,2],[4,1]]
  segs=[[0,1],[0,2],[2,3]] 
  
  lines = [[tuple(vertices[j]) for j in i]for i in segs]
  lc = matplotlib.collections.LineCollection(lines)
  
  fig, ax = matplotlib.pyplot.subplots()
  ax.add_collection(lc)
  matplotlib.pyplot.xlim([0,4])
  matplotlib.pyplot.ylim([0,2])
  matplotlib.pyplot.show()
  </code></pre>