Create a color generator from given colormap in matplotlib Create a color generator from given colormap in matplotlib python python

Create a color generator from given colormap in matplotlib


To index colors from a specific colormap you can use:

import pylabNUM_COLORS = 22cm = pylab.get_cmap('gist_rainbow')for i in range(NUM_COLORS):    color = cm(1.*i/NUM_COLORS)  # color will now be an RGBA tuple# or if you really want a generator:cgen = (cm(1.*i/NUM_COLORS) for i in range(NUM_COLORS))