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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
DOC: Regularize random data in example plots.
This ensures that the same plots are produced between builds.
  • Loading branch information
QuLogic committed Jan 2, 2016
commit 8314b8b4306318ca35996d5da1ab91ed275d0897
5 changes: 3 additions & 2 deletions examples/api/filled_step.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import itertools
from collections import OrderedDict
from functools import partial

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

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

# work with plain arrays
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(9, 4.5), tight_layout=True)
Expand Down
1 change: 1 addition & 0 deletions examples/pylab_examples/boxplot_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
randomDists = ['Normal(1,1)', ' Lognormal(1,1)', 'Exp(1)', 'Gumbel(6,4)',
'Triangular(2,9,11)']
N = 500
np.random.seed(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest adding a comment that the random seeding is only to make the example reproducible

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many of these in the examples without any comment; add them as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many issues with the examples so I wouldn't expect to fix all of them but I would like to do this in new examples

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

norm = np.random.normal(1, 1, N)
logn = np.random.lognormal(1, 1, N)
expo = np.random.exponential(1, N)
Expand Down
3 changes: 3 additions & 0 deletions examples/pylab_examples/spectrum_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import matplotlib.pyplot as plt
import numpy as np


np.random.seed(0)

dt = 0.01
Fs = 1/dt
t = np.arange(0, 10, dt)
Expand Down
20 changes: 10 additions & 10 deletions examples/pylab_examples/system_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import numpy as np


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


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


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


def get_stats():
return get_memory(), get_cpu(), get_net()
def get_stats(t):
return get_memory(t), get_cpu(t), get_net(t)

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


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

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

# update the animated artists
pm.set_height(m)
Expand Down
3 changes: 3 additions & 0 deletions examples/pylab_examples/xcorr_demo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import matplotlib.pyplot as plt
import numpy as np


np.random.seed(0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

x, y = np.random.randn(2, 100)
fig = plt.figure()
ax1 = fig.add_subplot(211)
Expand Down