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

Skip to content

Commit 9365d79

Browse files
committed
Major hist() revision
svn path=/trunk/matplotlib/; revision=5221
1 parent 5df852e commit 9365d79

6 files changed

Lines changed: 209 additions & 113 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2008-05-23 Major revision of hist(). Can handle 2D arrays and create
2+
stacked histogram plots; keyword 'width' deprecated and
3+
rwidth (relative width) introduced; align='edge' changed
4+
to center of bin - MM
5+
16
2008-05-22 Added support for ReST-based doumentation using Sphinx.
27
Documents are located in doc/, and are broken up into
38
a users guide and an API reference. To build, run the

examples/pylab/histogram_demo.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#!/usr/bin/env python
2-
from pylab import *
2+
import pylab as P
33

44
mu, sigma = 100, 15
5-
x = mu + sigma*randn(10000)
5+
x = mu + sigma*P.randn(10000)
66

77
# the histogram of the data
8-
n, bins, patches = hist(x, 50, normed=1)
9-
setp(patches, 'facecolor', 'g', 'alpha', 0.75)
8+
n, bins, patches = P.hist(x, 50, normed=1)
9+
P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
1010

1111
# add a 'best fit' line
12-
y = normpdf( bins, mu, sigma)
13-
l = plot(bins, y, 'r--')
14-
setp(l, 'linewidth', 1)
12+
y = P.normpdf( bins, mu, sigma)
13+
l = P.plot(bins, y, 'r--')
14+
P.setp(l, 'linewidth', 1)
1515

16-
xlabel('Smarts')
17-
ylabel('Probability')
18-
title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
19-
axis([40, 160, 0, 0.03])
20-
grid(True)
16+
P.xlabel('Smarts')
17+
P.ylabel('Probability')
18+
P.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
19+
P.axis([40, 160, 0, 0.03])
20+
P.grid(True)
2121

22-
#savefig('histogram_demo',dpi=72)
23-
show()
22+
#P.savefig('histogram_demo',dpi=72)
23+
P.show()

examples/pylab/histogram_demo_cumulative.py

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python
2+
import pylab as P
3+
4+
#
5+
# The hist() function now has a lot more options
6+
#
7+
8+
#
9+
# first create a single histogram
10+
#
11+
mu, sigma = 200, 25
12+
x = mu + sigma*P.randn(10000)
13+
14+
# the histogram of the data with histtype='step'
15+
n, bins, patches = P.hist(x, 50, normed=1, histtype='step')
16+
P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
17+
18+
# add a line showing the expected distribution
19+
y = P.normpdf( bins, mu, sigma)
20+
l = P.plot(bins, y, 'k--', linewidth=1.5)
21+
22+
23+
#
24+
# create a histogram by providing the bin edges (unequally spaced)
25+
#
26+
P.figure()
27+
28+
bins = [100,125,150,160,170,180,190,200,210,220,230,240,250,275,300]
29+
# the histogram of the data with histtype='step'
30+
n, bins, patches = P.hist(x, bins, normed=1, histtype='bar', rwidth=0.8)
31+
32+
#
33+
# now we create a cumulative histogram of the data
34+
#
35+
P.figure()
36+
37+
n, bins, patches = P.hist(x, 50, normed=1, histtype='step', cumulative=True)
38+
P.setp(patches, 'facecolor', 'b', 'alpha', 0.75)
39+
40+
# add a line showing the expected distribution
41+
y = P.normpdf( bins, mu, sigma).cumsum()
42+
y /= y[-1]
43+
l = P.plot(bins, y, 'k--', linewidth=1.5)
44+
45+
# create a second data-set with a smaller standard deviation
46+
sigma2 = 15.
47+
x = mu + sigma2*P.randn(10000)
48+
49+
n, bins, patches = P.hist(x, bins=bins, normed=1, histtype='step', cumulative=True)
50+
P.setp(patches, 'facecolor', 'r', 'alpha', 0.5)
51+
52+
# add a line showing the expected distribution
53+
y = P.normpdf( bins, mu, sigma2).cumsum()
54+
y /= y[-1]
55+
l = P.plot(bins, y, 'r--', linewidth=1.5)
56+
57+
P.grid(True)
58+
P.ylim(0, 1.05)
59+
60+
61+
#
62+
# histogram has the ability to plot multiple data in parallel ...
63+
#
64+
P.figure()
65+
66+
# create a new data-set
67+
x = mu + sigma*P.randn(1000,3)
68+
69+
n, bins, patches = P.hist(x, 10, normed=1, histtype='bar')
70+
71+
#
72+
# ... or we can stack the data
73+
#
74+
P.figure()
75+
76+
n, bins, patches = P.hist(x, 10, normed=1, histtype='barstacked')
77+
78+
79+
P.show()

examples/pylab/histogram_demo_step.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)