title: Matplotlib graph legend for multiple entries
body: <p>I am plotting several polygons in a plot:</p>
  
  <pre class="lang-py prettyprint-override"><code>from shapely.geometry import Polygon
  import matplotlib.pyplot as plt
  
  polygons.append(Polygon([(1,9), (4,9), (4,6), (1,6)]))
  polygons.append(Polygon([(7,9), (10,9), (10,6), (7,6)]))
  polygons.append(Polygon([(7,4), (10,4), (10,1), (7,1)]))
  polygons.append(Polygon([(1,4), (4,4), (4,1), (1,1)]))
  polygons.append(Polygon([(3,3), (3,7), (8,7), (8,3)]))
  
  plt.figure()
  for poly in polygons:
      plt.plot(*poly.exterior.xy)
  plt.show()
  </code></pre>
  
  <p>The resulting plot correctly show my polygons, but I would like to know which one corresponds to which index on the plot (eg: the green polygon is the polygon at <code>polygons[2]</code>). Ideally I'd like a legend that associates the colour of the polygon with its index, but I can not figure out how to add such a legend in a loop like this. I have tried <code>plt.legend(polygons.index(poly))</code> but that did not work.</p>
  
  <p>The amount of polygons is variable so strictly assigning colours is out of the question.</p>
  
  <p>How can I add a legend?</p>