I have found on the internet a way to use a colobar with only N colors. Here is the example
cmap = cm.jet
cmaplist = [cmap(i) for i in range(cmap.N)]
cmap = cmap.from_list('Custom cmap', cmaplist, cmap.N)
bounds = linspace(0,len(my_values),len(my_values)+1)
where my_values
is
my_values=array([0.,1.,2.,3.,4.,5.,6.])
Let's assume we have two arrays, x
and y
, that represent the position of random points. A third array, c
, is associated to each point and can only take values from my_values
.
The following code will plot a scatter plot and the colorbar is divided into 7 discrete levels.
scatter(x,y,c=c);colorbar(boundaris=bounds)
My question is, how can I retrieve the color (in rgb, hex or whatever) of each of the 7 levels?