|
15 | 15 |
|
16 | 16 | from utils import DATA_DIR, CHART_DIR |
17 | 17 |
|
18 | | -sp.random.seed(3) # to reproduce the data later on |
| 18 | +sp.random.seed(5) # to reproduce the data later on |
19 | 19 |
|
20 | 20 | x = sp.arange(1, 31*24) |
21 | 21 | y = sp.array(200*(sp.sin(2*sp.pi*x/(7*24))), dtype=int) |
22 | | -y += gamma.rvs(15, loc=0, scale=100, size=len(x)) |
23 | | -y += 2 * sp.exp(x/100.0) |
| 22 | +y += gamma.rvs(15, loc=0, scale=100, size=len(x)).astype('int64') |
| 23 | +y += 2 * sp.exp(x/100.0).astype('int64') |
24 | 24 | y = sp.ma.array(y, mask=[y<0]) |
25 | 25 | print(sum(y), sum(y<0)) |
26 | 26 |
|
27 | 27 | plt.scatter(x, y) |
28 | 28 | plt.title("Web traffic over the last month") |
29 | 29 | plt.xlabel("Time") |
30 | 30 | plt.ylabel("Hits/hour") |
31 | | -plt.xticks([w*7*24 for w in range(5)], |
| 31 | +plt.xticks([w*7*24 for w in range(5)], |
32 | 32 | ['week %i' %(w+1) for w in range(5)]) |
33 | 33 | plt.autoscale(tight=True) |
34 | 34 | plt.grid() |
35 | 35 | plt.savefig(os.path.join(CHART_DIR, "1400_01_01.png")) |
36 | 36 |
|
37 | | -sp.savetxt(os.path.join(DATA_DIR, "web_traffic.tsv"), |
| 37 | +sp.savetxt(os.path.join(DATA_DIR, "web_traffic.tsv"), |
38 | 38 | list(zip(x, y)), delimiter="\t", fmt="%s") |
0 commit comments