|
9 | 9 | matplotlib fun for a rainy day
|
10 | 10 | """
|
11 | 11 |
|
12 |
| -from pylab import * |
| 12 | +import matplotlib.pyplot as plt |
| 13 | +import numpy as np |
13 | 14 |
|
14 |
| -x = array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) |
15 |
| -y1 = array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) |
16 |
| -y2 = array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]) |
17 |
| -y3 = array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]) |
18 |
| -x4 = array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]) |
19 |
| -y4 = array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]) |
| 15 | +x = np.array([10, 8, 13, 9, 11, 14, 6, 4, 12, 7, 5]) |
| 16 | +y1 = np.array([8.04, 6.95, 7.58, 8.81, 8.33, 9.96, 7.24, 4.26, 10.84, 4.82, 5.68]) |
| 17 | +y2 = np.array([9.14, 8.14, 8.74, 8.77, 9.26, 8.10, 6.13, 3.10, 9.13, 7.26, 4.74]) |
| 18 | +y3 = np.array([7.46, 6.77, 12.74, 7.11, 7.81, 8.84, 6.08, 5.39, 8.15, 6.42, 5.73]) |
| 19 | +x4 = np.array([8, 8, 8, 8, 8, 8, 8, 19, 8, 8, 8]) |
| 20 | +y4 = np.array([6.58, 5.76, 7.71, 8.84, 8.47, 7.04, 5.25, 12.50, 5.56, 7.91, 6.89]) |
20 | 21 |
|
21 | 22 |
|
22 | 23 | def fit(x):
|
23 | 24 | return 3 + 0.5*x
|
24 | 25 |
|
25 | 26 |
|
26 |
| -xfit = array([amin(x), amax(x)]) |
| 27 | +xfit = np.array([np.amin(x), np.amax(x)]) |
27 | 28 |
|
28 |
| -subplot(221) |
29 |
| -plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2) |
30 |
| -axis([2, 20, 2, 14]) |
31 |
| -setp(gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) |
32 |
| -text(3, 12, 'I', fontsize=20) |
| 29 | +plt.subplot(221) |
| 30 | +plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2) |
| 31 | +plt.axis([2, 20, 2, 14]) |
| 32 | +plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) |
| 33 | +plt.text(3, 12, 'I', fontsize=20) |
33 | 34 |
|
34 |
| -subplot(222) |
35 |
| -plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) |
36 |
| -axis([2, 20, 2, 14]) |
37 |
| -setp(gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) |
38 |
| -text(3, 12, 'II', fontsize=20) |
| 35 | +plt.subplot(222) |
| 36 | +plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) |
| 37 | +plt.axis([2, 20, 2, 14]) |
| 38 | +plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) |
| 39 | +plt.text(3, 12, 'II', fontsize=20) |
39 | 40 |
|
40 |
| -subplot(223) |
41 |
| -plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2) |
42 |
| -axis([2, 20, 2, 14]) |
43 |
| -text(3, 12, 'III', fontsize=20) |
44 |
| -setp(gca(), yticks=(4, 8, 12), xticks=(0, 10, 20)) |
| 41 | +plt.subplot(223) |
| 42 | +plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2) |
| 43 | +plt.axis([2, 20, 2, 14]) |
| 44 | +plt.text(3, 12, 'III', fontsize=20) |
| 45 | +plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20)) |
45 | 46 |
|
46 |
| -subplot(224) |
| 47 | +plt.subplot(224) |
47 | 48 |
|
48 |
| -xfit = array([amin(x4), amax(x4)]) |
49 |
| -plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2) |
50 |
| -axis([2, 20, 2, 14]) |
51 |
| -setp(gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) |
52 |
| -text(3, 12, 'IV', fontsize=20) |
| 49 | +xfit = np.array([np.amin(x4), np.amax(x4)]) |
| 50 | +plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2) |
| 51 | +plt.axis([2, 20, 2, 14]) |
| 52 | +plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) |
| 53 | +plt.text(3, 12, 'IV', fontsize=20) |
53 | 54 |
|
54 | 55 | # verify the stats
|
55 | 56 | pairs = (x, y1), (x, y2), (x, y3), (x4, y4)
|
56 | 57 | for x, y in pairs:
|
57 |
| - print('mean=%1.2f, std=%1.2f, r=%1.2f' % (mean(y), std(y), corrcoef(x, y)[0][1])) |
| 58 | + print('mean=%1.2f, std=%1.2f, r=%1.2f' % (np.mean(y), np.std(y), np.corrcoef(x, y)[0][1])) |
58 | 59 |
|
59 |
| -show() |
| 60 | +plt.show() |
0 commit comments