Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf30677

Browse files
committed
colormapped histogram
svn path=/trunk/matplotlib/; revision=4572
1 parent 750e123 commit cf30677

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

examples/hist_colormapped.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as n
2+
from pylab import figure, show
3+
import matplotlib.cm as cm
4+
import matplotlib.colors as colors
5+
6+
fig = figure()
7+
ax = fig.add_subplot(111)
8+
Ntotal = 1000
9+
N, bins, patches = ax.hist(n.random.rand(Ntotal), 20)
10+
11+
#I'll color code by height, but you could use any scalar
12+
13+
14+
# we need to normalize the data to 0..1 for the full
15+
# range of the colormap
16+
fracs = N.astype(float)/N.max()
17+
norm = colors.normalize(fracs.min(), fracs.max())
18+
19+
for thisfrac, thispatch in zip(fracs, patches):
20+
color = cm.jet(norm(thisfrac))
21+
thispatch.set_facecolor(color)
22+
23+
24+
show()

0 commit comments

Comments
 (0)