Dear users,

I would like to generate a colored histogram using a colormap.

via

…

vals, bins, patchs = pylab.hist(hist_data ,75 ,normed=1)

…

Does anybody know how to assign a colormap to a histogram to find map data so that one can find easily data from a 2d map in the histogram?

Thanks a lot,

dirk

We need to rewrite histogram to use a PatchCollection, which would be

more efficient and would support colormapping out of the box. In the

current implementation, you can do it by using the colormap

normalization code and mapping manually on each rectangle. Here is an

example:

import numpy as n

from pylab import figure, show

import matplotlib.cm as cm

import matplotlib.colors as colors

fig = figure()

ax = fig.add_subplot(111)

Ntotal = 1000

N, bins, patches = ax.hist(n.random.rand(Ntotal), 20)

#I'll color code by height, but you could use any scalar

# we need to normalize the data to 0..1 for the full

# range of the colormap

fracs = N.astype(float)/N.max()

norm = colors.normalize(fracs.min(), fracs.max())

for thisfrac, thispatch in zip(fracs, patches):

color = cm.jet(norm(thisfrac))

thispatch.set_facecolor(color)

show()

## ···

On Dec 3, 2007 4:57 AM, Dirk Zickermann <dirk.zickermann@...982...> wrote:

Dear users,

I would like to generate a colored histogram using a colormap.

via

...

vals, bins, patchs = pylab.hist(hist_data ,75 ,normed=1)

..

Does anybody know how to assign a colormap to a histogram to find map data

so that one can find easily data from a 2d map in the histogram?