def gen_cmap_rgb(cols):
    nmax = float(len(cols)-1)
    cdict = {'red':[], 'green':[], 'blue':[]}
    for n, c in enumerate(cols):
        loc = n/nmax
        cdict['red'  ].append((loc, c[0], c[0]))
        cdict['green'].append((loc, c[1], c[1]))
        cdict['blue' ].append((loc, c[2], c[2]))
    return mpl.colors.LinearSegmentedColormap('cmap', cdict)

cmap = gen_cmap_rgb([(1,0,0),(1,1,0),(0,1,0),(0,1,1),(0,0,1)])