Colour generator for a stacked bar plot

Hi all,

I am looking for a simple method to generate various colours (n > 15, n denotes the number of colours) for a stacked bar plot.

Any pointer would be appreciated.

The example http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html
generates pastel colours. However the difference between the different colors decreases drastically.

Nils

Hi all,

I am looking for a simple method to generate various

colours (n > 15, n denotes the number of colours) for a

stacked bar plot.

Any pointer would be appreciated.

The example

http://matplotlib.sourceforge.net/examples/pylab_examples/table_demo.html

generates pastel colours. However the difference between

the different colors decreases drastically.

You might try using one or more of the default colormaps to generate colors. For example:

for n in np.linspace(0, 1, 20):
plt.plot(n, 0, ‘o’, mfc=plt.cm.Set1(n))

will
plot 20 points in a line with a different color for each dot. Nevertheless, some colors are difficult to differentiate. Instead of grabbing all your colors from one colormap you could grab the first 10 from a pastel colormap (e.g. ‘Set3’) and then the next 10 from a dark colormap (e.g. ‘Dark2’) and maybe even some more from a bright colormap (e.g. ‘spectral’).

You’ll probably have to tweak these colormaps before they are properly differentiated (i.e. you might not be able to get away with evenly-spaced indexes into the colormap), but something like this should
work.

Best,
-Tony

(Sorry for the duplicate email, Nils, but I forgot to reply all).

···

On Thu, Sep 15, 2011 at 7:12 AM, Nils Wagner <nwagner@…878…1052…> wrote: