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

Skip to content

Commit f57f3ad

Browse files
committed
DOC: Regularize random data in example plots.
This ensures that the same plots are produced between builds.
1 parent 094966f commit f57f3ad

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

examples/api/filled_step.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import itertools
2+
from collections import OrderedDict
23
from functools import partial
34

45
import numpy as np
@@ -174,9 +175,9 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
174175
hatch_cycle = cycler('hatch', ['/', '*', '+', '|'])
175176

176177
# make some synthetic data
178+
np.random.seed(0)
177179
stack_data = np.random.randn(4, 12250)
178-
dict_data = {lab: d for lab, d in zip(list(c['label'] for c in label_cycle),
179-
stack_data)}
180+
dict_data = OrderedDict(zip((c['label'] for c in label_cycle), stack_data))
180181

181182
# work with plain arrays
182183
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True)

examples/pylab_examples/boxplot_demo2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
randomDists = ['Normal(1,1)', ' Lognormal(1,1)', 'Exp(1)', 'Gumbel(6,4)',
1717
'Triangular(2,9,11)']
1818
N = 500
19+
np.random.seed(0)
1920
norm = np.random.normal(1, 1, N)
2021
logn = np.random.lognormal(1, 1, N)
2122
expo = np.random.exponential(1, N)

examples/pylab_examples/spectrum_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4+
5+
np.random.seed(0)
6+
47
dt = 0.01
58
Fs = 1/dt
69
t = np.arange(0, 10, dt)

examples/pylab_examples/system_monitor.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
import numpy as np
44

55

6-
def get_memory():
6+
def get_memory(t):
77
"Simulate a function that returns system memory"
8-
return 100*(0.5 + 0.5*np.sin(0.5*np.pi*time.time()))
8+
return 100 * (0.5 + 0.5 * np.sin(0.5 * np.pi * t))
99

1010

11-
def get_cpu():
11+
def get_cpu(t):
1212
"Simulate a function that returns cpu usage"
13-
return 100*(0.5 + 0.5*np.sin(0.2*np.pi*(time.time() - 0.25)))
13+
return 100 * (0.5 + 0.5 * np.sin(0.2 * np.pi * (t - 0.25)))
1414

1515

16-
def get_net():
16+
def get_net(t):
1717
"Simulate a function that returns network bandwidth"
18-
return 100*(0.5 + 0.5*np.sin(0.7*np.pi*(time.time() - 0.1)))
18+
return 100 * (0.5 + 0.5 * np.sin(0.7 * np.pi * (t - 0.1)))
1919

2020

21-
def get_stats():
22-
return get_memory(), get_cpu(), get_net()
21+
def get_stats(t):
22+
return get_memory(t), get_cpu(t), get_net(t)
2323

2424
fig, ax = plt.subplots()
2525
ind = np.arange(1, 4)
@@ -28,7 +28,7 @@ def get_stats():
2828
plt.show(block=False)
2929

3030

31-
pm, pc, pn = plt.bar(ind, get_stats())
31+
pm, pc, pn = plt.bar(ind, get_stats(0))
3232
centers = ind + 0.5*pm.get_width()
3333
pm.set_facecolor('r')
3434
pc.set_facecolor('g')
@@ -42,7 +42,7 @@ def get_stats():
4242

4343
start = time.time()
4444
for i in range(200): # run for a little while
45-
m, c, n = get_stats()
45+
m, c, n = get_stats(i / 10.0)
4646

4747
# update the animated artists
4848
pm.set_height(m)

examples/pylab_examples/xcorr_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4+
5+
np.random.seed(0)
6+
47
x, y = np.random.randn(2, 100)
58
fig = plt.figure()
69
ax1 = fig.add_subplot(211)

0 commit comments

Comments
 (0)