Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b90cd59

Browse filesBrowse files
committed
ENH examples are now reproducible
- added a random seed in every single example that needed one.
1 parent 5ac0881 commit b90cd59
Copy full SHA for b90cd59

File tree

Expand file treeCollapse file tree

105 files changed

+333
-27
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

105 files changed

+333
-27
lines changed

‎examples/animation/basic_example.py

Copy file name to clipboardExpand all lines: examples/animation/basic_example.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def update_line(num, data, line):
1818

1919
fig1 = plt.figure()
2020

21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
2124
data = np.random.rand(2, 25)
2225
l, = plt.plot([], [], 'r-')
2326
plt.xlim(0, 1)

‎examples/animation/basic_example_writer.py

Copy file name to clipboardExpand all lines: examples/animation/basic_example_writer.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def update_line(num, data, line):
2020
line.set_data(data[..., :num])
2121
return line,
2222

23+
# Fixing random state for reproducibility
24+
np.random.seed(19680801)
25+
26+
2327
# Set up formatting for the movie files
2428
Writer = animation.writers['ffmpeg']
2529
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

‎examples/animation/bayes_update.py

Copy file name to clipboardExpand all lines: examples/animation/bayes_update.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __call__(self, i):
5151
self.line.set_data(self.x, y)
5252
return self.line,
5353

54+
# Fixing random state for reproducibility
55+
np.random.seed(19680801)
56+
57+
5458
fig, ax = plt.subplots()
5559
ud = UpdateDist(ax, prob=0.7)
5660
anim = FuncAnimation(fig, ud, frames=np.arange(100), init_func=ud.init,

‎examples/animation/histogram.py

Copy file name to clipboardExpand all lines: examples/animation/histogram.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
fig, ax = plt.subplots()
1818

19+
# Fixing random state for reproducibility
20+
np.random.seed(19680801)
21+
1922
# histogram our data with numpy
2023
data = np.random.randn(1000)
2124
n, bins = np.histogram(data, 100)

‎examples/animation/moviewriter.py

Copy file name to clipboardExpand all lines: examples/animation/moviewriter.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
import matplotlib.pyplot as plt
1818
import matplotlib.animation as manimation
1919

20+
# Fixing random state for reproducibility
21+
np.random.seed(19680801)
22+
23+
2024
FFMpegWriter = manimation.writers['ffmpeg']
2125
metadata = dict(title='Movie Test', artist='Matplotlib',
2226
comment='Movie support!')

‎examples/animation/rain.py

Copy file name to clipboardExpand all lines: examples/animation/rain.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import matplotlib.pyplot as plt
1313
from matplotlib.animation import FuncAnimation
1414

15+
# Fixing random state for reproducibility
16+
np.random.seed(19680801)
17+
1518

1619
# Create new Figure and an Axes which fills it.
1720
fig = plt.figure(figsize=(7, 7))

‎examples/animation/random_data.py

Copy file name to clipboardExpand all lines: examples/animation/random_data.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import matplotlib.pyplot as plt
1212
import matplotlib.animation as animation
1313

14+
# Fixing random state for reproducibility
15+
np.random.seed(19680801)
16+
17+
1418
fig, ax = plt.subplots()
1519
line, = ax.plot(np.random.rand(10))
1620
ax.set_ylim(0, 1)

‎examples/animation/simple_3danim.py

Copy file name to clipboardExpand all lines: examples/animation/simple_3danim.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import mpl_toolkits.mplot3d.axes3d as p3
1111
import matplotlib.animation as animation
1212

13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1316

1417
def Gen_RandLine(length, dims=2):
1518
"""

‎examples/animation/strip_chart_demo.py

Copy file name to clipboardExpand all lines: examples/animation/strip_chart_demo.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def emitter(p=0.03):
4747
else:
4848
yield np.random.rand(1)
4949

50+
# Fixing random state for reproducibility
51+
np.random.seed(19680801)
52+
53+
5054
fig, ax = plt.subplots()
5155
scope = Scope(ax)
5256

‎examples/animation/unchained.py

Copy file name to clipboardExpand all lines: examples/animation/unchained.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import matplotlib.pyplot as plt
1313
import matplotlib.animation as animation
1414

15+
# Fixing random state for reproducibility
16+
np.random.seed(19680801)
17+
18+
1519
# Create new Figure with black background
1620
fig = plt.figure(figsize=(8, 8), facecolor='black')
1721

‎examples/api/bbox_intersect.py

Copy file name to clipboardExpand all lines: examples/api/bbox_intersect.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from matplotlib.transforms import Bbox
44
from matplotlib.path import Path
55

6+
# Fixing random state for reproducibility
7+
np.random.seed(19680801)
8+
9+
610
left, bottom, width, height = (-1, -1, 2, 2)
711
rect = plt.Rectangle((left, bottom), width, height, facecolor="#aaaaaa")
812

‎examples/api/collections_demo.py

Copy file name to clipboardExpand all lines: examples/api/collections_demo.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
spiral = list(zip(xx, yy))
3232

3333
# Make some offsets
34-
rs = np.random.RandomState([12345678])
34+
# Fixing random state for reproducibility
35+
rs = np.random.RandomState(19680801)
36+
37+
3538
xo = rs.randn(npts)
3639
yo = rs.randn(npts)
3740
xyo = list(zip(xo, yo))

‎examples/api/engineering_formatter.py

Copy file name to clipboardExpand all lines: examples/api/engineering_formatter.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from matplotlib.ticker import EngFormatter
99

10-
prng = np.random.RandomState(123)
10+
# Fixing random state for reproducibility
11+
prng = np.random.RandomState(19680801)
1112

1213
fig, ax = plt.subplots()
1314
ax.set_xscale('log')

‎examples/api/filled_step.py

Copy file name to clipboardExpand all lines: examples/api/filled_step.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
176176
label_cycle = cycler('label', ['set {n}'.format(n=n) for n in range(4)])
177177
hatch_cycle = cycler('hatch', ['/', '*', '+', '|'])
178178

179-
# make some synthetic data
180-
np.random.seed(0)
179+
# Fixing random state for reproducibility
180+
np.random.seed(19680801)
181+
181182
stack_data = np.random.randn(4, 12250)
182183
dict_data = OrderedDict(zip((c['label'] for c in label_cycle), stack_data))
183184

‎examples/api/histogram_path_demo.py

Copy file name to clipboardExpand all lines: examples/api/histogram_path_demo.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
fig, ax = plt.subplots()
1919

20+
# Fixing random state for reproducibility
21+
np.random.seed(19680801)
22+
23+
2024
# histogram our data with numpy
25+
2126
data = np.random.randn(1000)
2227
n, bins = np.histogram(data, 50)
2328

‎examples/api/image_zcoord.py

Copy file name to clipboardExpand all lines: examples/api/image_zcoord.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import matplotlib.pyplot as plt
77
import matplotlib.cm as cm
88

9+
# Fixing random state for reproducibility
10+
np.random.seed(19680801)
11+
12+
913
X = 10*np.random.rand(5, 3)
1014

1115
fig, ax = plt.subplots()

‎examples/api/line_with_text.py

Copy file name to clipboardExpand all lines: examples/api/line_with_text.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def draw(self, renderer):
4444
lines.Line2D.draw(self, renderer)
4545
self.text.draw(renderer)
4646

47+
# Fixing random state for reproducibility
48+
np.random.seed(19680801)
49+
4750

4851
fig, ax = plt.subplots()
4952
x, y = np.random.rand(2, 20)

‎examples/api/patch_collection.py

Copy file name to clipboardExpand all lines: examples/api/patch_collection.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
from matplotlib.collections import PatchCollection
55
import matplotlib.pyplot as plt
66

7+
# Fixing random state for reproducibility
8+
np.random.seed(19680801)
9+
710

811
fig, ax = plt.subplots()
912

‎examples/api/unicode_minus.py

Copy file name to clipboardExpand all lines: examples/api/unicode_minus.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import matplotlib
1111
import matplotlib.pyplot as plt
1212

13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
16+
1317
matplotlib.rcParams['axes.unicode_minus'] = False
1418
fig, ax = plt.subplots()
1519
ax.plot(10*np.random.randn(100), 10*np.random.randn(100), 'o')

‎examples/api/watermark_image.py

Copy file name to clipboardExpand all lines: examples/api/watermark_image.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import matplotlib.image as image
1010
import matplotlib.pyplot as plt
1111

12+
# Fixing random state for reproducibility
13+
np.random.seed(19680801)
14+
15+
1216
datafile = cbook.get_sample_data('logo2.png', asfileobj=False)
1317
print('loading %s' % datafile)
1418
im = image.imread(datafile)

‎examples/api/watermark_text.py

Copy file name to clipboardExpand all lines: examples/api/watermark_text.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import matplotlib.pyplot as plt
99

10+
# Fixing random state for reproducibility
11+
np.random.seed(19680801)
12+
13+
1014
fig, ax = plt.subplots()
1115
ax.plot(np.random.rand(20), '-o', ms=20, lw=2, alpha=0.7, mfc='orange')
1216
ax.grid()

‎examples/axes_grid1/scatter_hist.py

Copy file name to clipboardExpand all lines: examples/axes_grid1/scatter_hist.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
import matplotlib.pyplot as plt
33
from mpl_toolkits.axes_grid1 import make_axes_locatable
44

5+
# Fixing random state for reproducibility
6+
np.random.seed(19680801)
7+
8+
59
# the random data
610
x = np.random.randn(1000)
711
y = np.random.randn(1000)

‎examples/axisartist/demo_floating_axes.py

Copy file name to clipboardExpand all lines: examples/axisartist/demo_floating_axes.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
DictFormatter)
2020
import matplotlib.pyplot as plt
2121

22+
# Fixing random state for reproducibility
23+
np.random.seed(19680801)
24+
2225

2326
def setup_axes1(fig, rect):
2427
"""

‎examples/event_handling/data_browser.py

Copy file name to clipboardExpand all lines: examples/event_handling/data_browser.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def update(self):
7171

7272
if __name__ == '__main__':
7373
import matplotlib.pyplot as plt
74+
# Fixing random state for reproducibility
75+
np.random.seed(19680801)
7476

7577
X = np.random.rand(100, 200)
7678
xs = np.mean(X, axis=1)

‎examples/event_handling/keypress_demo.py

Copy file name to clipboardExpand all lines: examples/event_handling/keypress_demo.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ def press(event):
1515
xl.set_visible(not visible)
1616
fig.canvas.draw()
1717

18+
# Fixing random state for reproducibility
19+
np.random.seed(19680801)
20+
21+
1822
fig, ax = plt.subplots()
1923

2024
fig.canvas.mpl_connect('key_press_event', press)

‎examples/event_handling/looking_glass.py

Copy file name to clipboardExpand all lines: examples/event_handling/looking_glass.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import numpy as np
22
import matplotlib.pyplot as plt
33
import matplotlib.patches as patches
4+
5+
# Fixing random state for reproducibility
6+
np.random.seed(19680801)
7+
48
x, y = np.random.rand(2, 200)
59

610
fig, ax = plt.subplots()

‎examples/images_contours_and_fields/interpolation_methods.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/interpolation_methods.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric',
1919
'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos']
2020

21-
np.random.seed(0)
21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
2224
grid = np.random.rand(4, 4)
2325

2426
fig, axes = plt.subplots(3, 6, figsize=(12, 6),

‎examples/lines_bars_and_markers/barh_demo.py

Copy file name to clipboardExpand all lines: examples/lines_bars_and_markers/barh_demo.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import matplotlib.pyplot as plt
55
import numpy as np
66

7+
# Fixing random state for reproducibility
8+
np.random.seed(19680801)
9+
710

811
plt.rcdefaults()
912
fig, ax = plt.subplots()

‎examples/misc/multiprocess.py

Copy file name to clipboardExpand all lines: examples/misc/multiprocess.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
import matplotlib.pyplot as plt
1414
import gobject
1515

16+
# Fixing random state for reproducibility
17+
np.random.seed(19680801)
18+
1619

1720
class ProcessPlotter(object):
1821
def __init__(self):

‎examples/mplot3d/2dcollections3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/2dcollections3d_demo.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
# Plot scatterplot data (20 2D points per colour) on the x and z axes.
1919
colors = ('r', 'g', 'b', 'k')
20+
21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
2024
x = np.random.sample(20*len(colors))
2125
y = np.random.sample(20*len(colors))
2226
c_list = []

‎examples/mplot3d/bars3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/bars3d_demo.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10+
# Fixing random state for reproducibility
11+
np.random.seed(19680801)
12+
13+
1014
fig = plt.figure()
1115
ax = fig.add_subplot(111, projection='3d')
1216

‎examples/mplot3d/hist3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/hist3d_demo.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import matplotlib.pyplot as plt
77
import numpy as np
88

9+
# Fixing random state for reproducibility
10+
np.random.seed(19680801)
11+
12+
913
fig = plt.figure()
1014
ax = fig.add_subplot(111, projection='3d')
1115
x, y = np.random.rand(2, 100) * 4

‎examples/mplot3d/polys3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/polys3d_demo.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
from matplotlib import colors as mcolors
1010
import numpy as np
1111

12+
# Fixing random state for reproducibility
13+
np.random.seed(19680801)
14+
1215

1316
def cc(arg):
1417
'''

‎examples/mplot3d/scatter3d_demo.py

Copy file name to clipboardExpand all lines: examples/mplot3d/scatter3d_demo.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212

13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1316

1417
def randrange(n, vmin, vmax):
1518
'''

‎examples/pie_and_polar_charts/pie_demo_features.py

Copy file name to clipboardExpand all lines: examples/pie_and_polar_charts/pie_demo_features.py
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""
1919
import matplotlib.pyplot as plt
2020

21+
2122
# The slices will be ordered and plotted counter-clockwise.
2223
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
2324
sizes = [15, 30, 45, 10]
@@ -32,6 +33,10 @@
3233
ax = fig.gca()
3334
import numpy as np
3435

36+
# Fixing random state for reproducibility
37+
np.random.seed(19680801)
38+
39+
3540
ax.pie(np.random.random(4), explode=explode, labels=labels,
3641
autopct='%1.1f%%', shadow=True, startangle=90,
3742
radius=0.25, center=(0, 0), frame=True)

‎examples/pie_and_polar_charts/polar_bar_demo.py

Copy file name to clipboardExpand all lines: examples/pie_and_polar_charts/polar_bar_demo.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import numpy as np
55
import matplotlib.pyplot as plt
66

7+
# Fixing random state for reproducibility
8+
np.random.seed(19680801)
79

810
N = 20
911
theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.