On Dec 3, 2007 4:57 AM, Dirk Zickermann <[EMAIL PROTECTED]> 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?

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()

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to