On Apr 8, 2010, at 8:13 AM, KrishnaPribadi wrote: > > Hi, > I'm trying to plot a set of lines, 12 to be exact, and the default color > cycle only supports 8 or 9 distinct colors. That said, I looked up the color > maps and segmented it using 12 constant intervals with the hope of getting > 12 distinct colors. > > The problem I'm running in to is that some of the line colors I get are too > close to each other. This is because come shades in the colormap have a > broader spectrum than others. > > Here is my code to set my custom default color cycle: > > import matplotlib as mpl > cmap = mpl.cm.get_cmap(name='spectral') #I gues we can also use > "hsv" or "gist_rainbow" > nColors = 12 #number of colors > incr = 0.9 / nColors > > self.mycolors = [] > for i in np.arange(0,0.9,incr): > self.mycolors.append(cmap(i))
you could replace the loop with a list comprehension: >>> mycolors = [cmap(i) for i in np.arange(0,0.9,incr)] Also, arange may not be a great fit for this task; maybe linspace would work better: >>> mycolors = [cmap(i) for i in np.linspace(0, 0.9, nColors)] This allows you to eliminate the assignment of `incr`. Note: the above colormap is different than that created by arange because linspace includes the endpoint, while arange doesn't. Hope that helps, -Tony > > mpl.axes.set_default_color_cycle(self.mycolors) > > Can anyone suggest a cleaner method? Or is there perhaps an existing class > to provide distinct color lines? > > Thanks, > Krishna ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users