title: Scatter plot colorbar - Matplotlib
body: <p>I'm trying to show a color bar of my scatter plot but I'm keep getting the error:</p>
  
  <blockquote>
    <p>TypeError: You must first set_array for mappable</p>
  </blockquote>
  
  <p>This is what I'm doing to plot:</p>
  
  <pre><code># Just plotting the values of data that are nonzero 
  x_data = numpy.nonzero(data)[0] # x coordinates
  y_data = numpy.nonzero(data)[1] # y coordinates
  
  # Mapping the values to RGBA colors
  data = plt.cm.jet(data[x_data, y_data])
  
  pts = plt.scatter(x_data, y_data, marker='s', color=data)
  
  plt.colorbar(pts)
  </code></pre>
  
  <p>If I comment the line <code>plt.colorbar(pts)</code> I got the plot correctly, but I would like to plot the color bar too.</p>
  
  <p>Thank you in advance.</p>