Skip to content

Commit c25ef1e

Browse files
committed
Use consistent imports
1 parent 8bec412 commit c25ef1e

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed
Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
2-
import pylab as P
2+
import matplotlib.pyplot as plt
3+
from matplotlib.mlab import normpdf
34

45
#
56
# The hist() function now has a lot more options
@@ -9,98 +10,98 @@
910
# first create a single histogram
1011
#
1112
mu, sigma = 200, 25
12-
x = mu + sigma*P.randn(10000)
13+
x = mu + sigma*np.random.randn(10000)
1314

1415
# the histogram of the data with histtype='step'
15-
n, bins, patches = P.hist(x, 50, normed=1, histtype='stepfilled')
16-
P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
16+
n, bins, patches = plt.hist(x, 50, normed=1, histtype='stepfilled')
17+
plt.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
1718

1819
# add a line showing the expected distribution
19-
y = P.normpdf( bins, mu, sigma)
20-
l = P.plot(bins, y, 'k--', linewidth=1.5)
20+
y = normpdf( bins, mu, sigma)
21+
l = plt.plot(bins, y, 'k--', linewidth=1.5)
2122

2223

2324
#
2425
# create a histogram by providing the bin edges (unequally spaced)
2526
#
26-
P.figure()
27+
plt.figure()
2728

2829
bins = [100,125,150,160,170,180,190,200,210,220,230,240,250,275,300]
2930
# the histogram of the data with histtype='step'
30-
n, bins, patches = P.hist(x, bins, normed=1, histtype='bar', rwidth=0.8)
31+
n, bins, patches = plt.hist(x, bins, normed=1, histtype='bar', rwidth=0.8)
3132

3233
#
3334
# now we create a cumulative histogram of the data
3435
#
35-
P.figure()
36+
plt.figure()
3637

37-
n, bins, patches = P.hist(x, 50, normed=1, histtype='step', cumulative=True)
38+
n, bins, patches = plt.hist(x, 50, normed=1, histtype='step', cumulative=True)
3839

3940
# add a line showing the expected distribution
40-
y = P.normpdf( bins, mu, sigma).cumsum()
41+
y = normpdf( bins, mu, sigma).cumsum()
4142
y /= y[-1]
42-
l = P.plot(bins, y, 'k--', linewidth=1.5)
43+
l = plt.plot(bins, y, 'k--', linewidth=1.5)
4344

4445
# create a second data-set with a smaller standard deviation
4546
sigma2 = 15.
46-
x = mu + sigma2*P.randn(10000)
47+
x = mu + sigma2*np.random.randn(10000)
4748

48-
n, bins, patches = P.hist(x, bins=bins, normed=1, histtype='step', cumulative=True)
49+
n, bins, patches = plt.hist(x, bins=bins, normed=1, histtype='step', cumulative=True)
4950

5051
# add a line showing the expected distribution
51-
y = P.normpdf( bins, mu, sigma2).cumsum()
52+
y = normpdf( bins, mu, sigma2).cumsum()
5253
y /= y[-1]
53-
l = P.plot(bins, y, 'r--', linewidth=1.5)
54+
l = plt.plot(bins, y, 'r--', linewidth=1.5)
5455

5556
# finally overplot a reverted cumulative histogram
56-
n, bins, patches = P.hist(x, bins=bins, normed=1,
57+
n, bins, patches = plt.hist(x, bins=bins, normed=1,
5758
histtype='step', cumulative=-1)
5859

5960

60-
P.grid(True)
61-
P.ylim(0, 1.05)
61+
plt.grid(True)
62+
plt.ylim(0, 1.05)
6263

6364

6465
#
6566
# histogram has the ability to plot multiple data in parallel ...
6667
# Note the new color kwarg, used to override the default, which
6768
# uses the line color cycle.
6869
#
69-
P.figure()
70+
plt.figure()
7071

7172
# create a new data-set
72-
x = mu + sigma*P.randn(1000,3)
73+
x = mu + sigma*np.random.randn(1000,3)
7374

74-
n, bins, patches = P.hist(x, 10, normed=1, histtype='bar',
75+
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar',
7576
color=['crimson', 'burlywood', 'chartreuse'],
7677
label=['Crimson', 'Burlywood', 'Chartreuse'])
77-
P.legend()
78+
plt.legend()
7879

7980
#
8081
# ... or we can stack the data
8182
#
82-
P.figure()
83+
plt.figure()
8384

84-
n, bins, patches = P.hist(x, 10, normed=1, histtype='bar', stacked=True)
85+
n, bins, patches = plt.hist(x, 10, normed=1, histtype='bar', stacked=True)
8586

86-
P.show()
87+
plt.show()
8788

8889
#
8990
# we can also stack using the step histtype
9091
#
9192

92-
P.figure()
93+
plt.figure()
9394

94-
n, bins, patches = P.hist(x, 10, histtype='step', stacked=True, fill=True)
95+
n, bins, patches = plt.hist(x, 10, histtype='step', stacked=True, fill=True)
9596

96-
P.show()
97+
plt.show()
9798

9899
#
99100
# finally: make a multiple-histogram of data-sets with different length
100101
#
101-
x0 = mu + sigma*P.randn(10000)
102-
x1 = mu + sigma*P.randn(7000)
103-
x2 = mu + sigma*P.randn(3000)
102+
x0 = mu + sigma*np.random.randn(10000)
103+
x1 = mu + sigma*np.random.randn(7000)
104+
x2 = mu + sigma*np.random.randn(3000)
104105

105106
# and exercise the weights option by arbitrarily giving the first half
106107
# of each series only half the weight of the others:
@@ -114,8 +115,8 @@
114115

115116

116117

117-
P.figure()
118+
plt.figure()
118119

119-
n, bins, patches = P.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
120+
n, bins, patches = plt.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
120121

121-
P.show()
122+
plt.show()

0 commit comments

Comments
 (0)