It's common to want lists of colors for plotting, for heat maps or the RNA secondary structure plot from the other day (here). If you're doing this for a real project, I'd recommend matplotlib's
LinearSegmentedColormap
, which looks complicated but isn't hard to understand---I posted about it here.Another option is to get the colors from R, either by getting R to write them to a file on disk, or using RPy. I posted about the former method before too (here). RColorBrewer has some great color schemes.
Finally, we can make our own list. It seems like a nice problem that exercises simple Python skills. The chief goal is flexibility. The core function in the code below assembles a list of tuples of rgb values, where each value is either a constant for the current series, or drawn from the hex values in order (either 00 to FF or reversed FF to 00).
The function's signature is:
series(r=None,g=None,b=None,rev='')
If a value is given for r, g, or b, that's the constant to use. Otherwise, we grab the list. For each of 'r','g', or 'b' that is contained in rev, we reverse the list. The second function simply assembles the color list. To show it in action, we make a list with 5 components: purple to blue, blue to cyan, cyan to green, green to yellow and yellow to red. The results are plotted with matplotlib.
code listing: