title: Scatter plot with colors and legends
body: <p>I am having a hard time trying to create a scatter plot that will show points of different classes with different colors and the corresponding label of the class in the legend.</p>
  
  <p>I have 52 samples, 2 features and 3 classes(class 1,2 and 3). The data are in <code>X</code> array and the labels in <code>labels</code> array.</p>
  
  <p>I want to plot the legend that will contain the class names (1,2 and 3) for the corresponding colors.</p>
  
  <hr>
  
  <p><strong>My code</strong>:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x = np.random.rand(52,2)
  
  labels = np.ones(x.shape[0])
  labels[0:8] = 1
  labels[8:31] = 2 
  labels[31:] = 3
  
  plt.scatter(x[:,0], x[:,1], c = labels, label = labels)
  plt.legend()
  plt.show()
  </code></pre>
  
  <hr>
  
  <p><strong>Result</strong>:</p>
  
  <p><a href="https://i.stack.imgur.com/ySrY9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ySrY9.png" alt="enter image description here"></a></p>