[Matplotlib-users] Setting colors for hist

 [Matplotlib-users] Setting colors for hist From: Jeff Klukas - 2010-03-26 15:47:14 ```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 || University of Wisconsin -- Madison || jeff.klukas@... | jeffyklukas@... | jeffklukas@... || http://www.hep.wisc.edu/~jklukas/ ```

 [Matplotlib-users] Setting colors for hist From: Jeff Klukas - 2010-03-26 15:47:14 ```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 || University of Wisconsin -- Madison || jeff.klukas@... | jeffyklukas@... | jeffklukas@... || http://www.hep.wisc.edu/~jklukas/ ```
 Re: [Matplotlib-users] Setting colors for hist From: Jeff Klukas - 2010-03-26 19:28:10 ```I was not aware of color cycles, but it looks like this is the way to go about solving my problem. 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() ----------------------------------- ```