0

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?

Brian
  • 13,996
  • 19
  • 70
  • 94
  • 1
    Your example looks similar to [this](http://stackoverflow.com/questions/14777066/matplotlib-discrete-colorbar). You may look into [this question](http://stackoverflow.com/questions/8931268/using-colormaps-to-set-color-of-line-in-matplotlib) which discusses using [ScalarMappable](http://matplotlib.org/api/cm_api.html) from `matplotlib.cm`. – wflynny Jun 25 '13 at 17:31
  • thanks, it actually did the trick – Brian Jun 26 '13 at 08:20

0 Answers0