Create a color generator in matplotlib
Posted
by Brendan
on Stack Overflow
See other posts from Stack Overflow
or by Brendan
Published on 2010-06-10T16:18:14Z
Indexed on
2010/06/10
23:52 UTC
Read the original article
Hit count: 302
python
|matplotlib
I have a series of lines that each need to be plotted with a separate colour. Each line is actually made up of several data sets (positive, negative regions etc.) and so I'd like to be able to create a generator that will feed one colour at a time across a spectrum, for example the gist_rainbow
map shown here.
I have found the following works but it seems very complicated and more importantly difficult to remember,
from pylab import *
NUM_COLORS = 22
mp = cm.datad['gist_rainbow']
get_color = matplotlib.colors.LinearSegmentedColormap.from_list(mp, colors=['r', 'b'], N=NUM_COLORS)
...
# Then in a for loop
this_color = get_color(float(i)/NUM_COLORS)
Moreover, it does not cover the range of colours in the gist_rainbow
map, I have to redefine a map.
Maybe a generator is not the best way to do this, if so what is the accepted way?
© Stack Overflow or respective owner