 # Setting colors for hist

In the extended histogram demo:
http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html?highlight=codex%20hist

Multiple data are shown in parallel with different colors, using a
single hist command. These colors seem to be automatically chosen,
however, and I cannot figure out a way to control them.

The color kwarg description says that it accepts "matplotlib color arg
or sequence of rgba tuples", but giving it a list of rgba tuples
raises an error.

Am I approaching this the wrong way? Has anybody successfully done this?

Example that raises error:

···

----------------------------------
import pylab as P

mu, sigma = 200, 25

x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

# The following gives a ValueError from to_rgba
n, bins, patches = P.hist([x0,x1,x2], 50, normed=1, histtype='bar',
color=[(.5, 0., 0., 1.), (0., .5, 0., 1.),])

P.show()
-----------------------------------

Many thanks,
Jeff

Jeff Klukas, Research Assistant, Physics
jeff.klukas@...3030... | jeffyklukas@...3031... | jeffklukas@...3032...
http://www.hep.wisc.edu/~jklukas/

I was not aware of color cycles, but it looks like this is the way to

Below is an example that actually works.

···

----------------------------------
import pylab as P

mu, sigma = 200, 25

x0 = mu + sigma*P.randn(10000)
x1 = mu + sigma*P.randn(7000)
x2 = mu + sigma*P.randn(3000)

# Set the color cycle of the axes rather than using a kwarg
P.gca().set_color_cycle([(0.5,0.,0.),
(0.,0.5,0.),
(0.,0.,0.5)])
n, bins, patches = P.hist([x0,x1,x2], 50, normed=1, histtype='bar')

P.show()
-----------------------------------