I'm trying to show a color bar of my scatter plot but I'm keep getting the error:
TypeError: You must first set_array for mappable
This is what I'm doing to plot:
# 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)
If I comment the line plt.colorbar(pts)
I got the plot correctly, but I would like to plot the color bar too.
Thank you in advance.