title: Add legend to scatter plot
body: <p>This question has been asked on SO, but I want to find a clearer solution.</p>
  
  <p>Given X is 100x2 data, and labels is the label vector ( from 1 to 9) I plot the scatter plot as following:</p>
  
  <pre><code>pl.scatter(X[:,0], X[:,1], c = labels)
  pl.show()
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/uOdAR.png" alt="enter image description here"></p>
  
  <p>How to add legend to explain the colors in just one line of code? Other solutions plot each label separately:</p>
  
  <pre><code>a = pl.scatter(X1[:,0], X1[:,1], color = "red")
  b = pl.scatter(X2[:,0], X2[:,1], color = "green")
  c = pl.scatter(X3[:,0], X3[:,1], color = "blue")
  pl.legend((a,b,c), ("line 1", "line 2", "line 3")
  pl.show()
  </code></pre>