Skip to content

Commit c576358

Browse files
committed
DOC: Add seeds to examples for reproducibility.
1 parent beb7282 commit c576358

22 files changed

+87
-3
lines changed

examples/axes_grid1/demo_anchored_direction_arrows.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDirectionArrows
1010
import matplotlib.font_manager as fm
1111

12+
13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1216
fig, ax = plt.subplots()
1317
ax.imshow(np.random.random((10, 10)))
1418

examples/event_handling/image_slices_viewer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import matplotlib.pyplot as plt
1111

1212

13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
16+
1317
class IndexTracker:
1418
def __init__(self, ax, X):
1519
self.ax = ax

examples/event_handling/pick_event_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def pick_handler(event):
7070
from numpy.random import rand
7171

7272

73+
# Fixing random state for reproducibility
74+
np.random.seed(19680801)
75+
76+
7377
def pick_simple():
7478
# simple picking, lines, rectangles and text
7579
fig, (ax1, ax2) = plt.subplots(2, 1)

examples/event_handling/pick_event_demo2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import matplotlib.pyplot as plt
1212

1313

14+
# Fixing random state for reproducibility
15+
np.random.seed(19680801)
16+
1417
X = np.random.rand(100, 1000)
1518
xs = np.mean(X, axis=1)
1619
ys = np.std(X, axis=1)

examples/event_handling/zoom_window.py

Lines 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 numpy as np
1919

20+
21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
2024
figsrc, axsrc = plt.subplots()
2125
figzoom, axzoom = plt.subplots()
2226
axsrc.set(xlim=(0, 1), ylim=(0, 1), autoscale_on=False,

examples/images_contours_and_fields/image_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
from matplotlib.path import Path
1818
from matplotlib.patches import PathPatch
1919

20+
21+
# Fixing random state for reproducibility
22+
np.random.seed(19680801)
23+
2024
###############################################################################
2125
# First we'll generate a simple bivariate normal distribution.
2226

examples/images_contours_and_fields/pcolor_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import numpy as np
1313
from matplotlib.colors import LogNorm
1414

15+
16+
# Fixing random state for reproducibility
17+
np.random.seed(19680801)
18+
1519
###############################################################################
1620
# A simple pcolor demo
1721
# --------------------

examples/images_contours_and_fields/spy_demos.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import matplotlib.pyplot as plt
1010
import numpy as np
1111

12+
13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1216
fig, axs = plt.subplots(2, 2)
1317
ax1 = axs[0, 0]
1418
ax2 = axs[0, 1]

examples/lines_bars_and_markers/scatter_custom_symbol.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import matplotlib.pyplot as plt
1010
import numpy as np
1111

12+
13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1216
# unit area ellipse
1317
rx, ry = 3., 1.
1418
area = rx * ry * np.pi

examples/lines_bars_and_markers/stackplot_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import numpy as np
1313
import matplotlib.pyplot as plt
1414

15+
16+
# Fixing random state for reproducibility
17+
np.random.seed(19680801)
18+
1519
x = [1, 2, 3, 4, 5]
1620
y1 = [1, 1, 2, 3, 5]
1721
y2 = [0, 4, 2, 6, 8]

examples/lines_bars_and_markers/vline_hline_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import numpy as np
1111

1212

13+
# Fixing random state for reproducibility
14+
np.random.seed(19680801)
15+
1316
t = np.arange(0.0, 5.0, 0.1)
1417
s = np.exp(-t) + np.sin(2 * np.pi * t) + 1
1518
nse = np.random.normal(0.0, 0.3, t.shape) * s

examples/recipes/create_subplots.py

Lines 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 numpy as np
1313

14+
15+
# Fixing random state for reproducibility
16+
np.random.seed(19680801)
17+
1418
x = np.random.randn(50)
1519

1620
# old style

examples/recipes/fill_between_alpha.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import numpy as np
1717
import matplotlib.cbook as cbook
1818

19+
20+
# Fixing random state for reproducibility
21+
np.random.seed(19680801)
22+
1923
# load up some sample financial data
2024
with cbook.get_sample_data('goog.npz') as datafile:
2125
r = np.load(datafile)['price_data'].view(np.recarray)

examples/scales/power_norm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import numpy as np
1313
from numpy.random import multivariate_normal
1414

15+
16+
# Fixing random state for reproducibility.
17+
np.random.seed(19680801)
18+
1519
data = np.vstack([
1620
multivariate_normal([10, 10], [[3, 2], [2, 3]], size=100000),
1721
multivariate_normal([30, 20], [[3, 1], [1, 3]], size=1000)

examples/shapes_and_collections/ellipse_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
import numpy as np
1212
from matplotlib.patches import Ellipse
1313

14+
15+
# Fixing random state for reproducibility
16+
np.random.seed(19680801)
17+
1418
NUM = 250
1519

1620
ells = [Ellipse(xy=np.random.rand(2) * 10,

examples/style_sheets/bmh.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
.. [1] http://camdavidsonpilon.github.io/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/
1010
1111
"""
12-
from numpy.random import beta
12+
import numpy as np
1313
import matplotlib.pyplot as plt
1414

1515

16+
# Fixing random state for reproducibility
17+
np.random.seed(19680801)
18+
1619
plt.style.use('bmh')
1720

1821

1922
def plot_beta_hist(ax, a, b):
20-
ax.hist(beta(a, b, size=10000), histtype="stepfilled",
21-
bins=25, alpha=0.8, density=True)
23+
ax.hist(np.random.beta(a, b, size=10000),
24+
histtype="stepfilled", bins=25, alpha=0.8, density=True)
2225

2326

2427
fig, ax = plt.subplots()

examples/style_sheets/plot_solarizedlight2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
"""
2424
import matplotlib.pyplot as plt
2525
import numpy as np
26+
27+
28+
# Fixing random state for reproducibility
29+
np.random.seed(19680801)
30+
2631
x = np.linspace(0, 10)
2732
with plt.style.context('Solarize_Light2'):
2833
plt.plot(x, np.sin(x) + x + np.random.randn(50))

examples/subplots_axes_and_figures/axes_box_aspect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080

8181
fig4, (ax, ax2) = plt.subplots(ncols=2, constrained_layout=True)
8282

83+
np.random.seed(19680801) # Fixing random state for reproducibility
8384
im = np.random.rand(16, 27)
8485
ax.imshow(im)
8586

@@ -106,6 +107,7 @@
106107
axs[1, 0].set_box_aspect(1)
107108
axs[1, 1].set_box_aspect(3/1)
108109

110+
np.random.seed(19680801) # Fixing random state for reproducibility
109111
x, y = np.random.randn(2, 400) * [[.5], [180]]
110112
axs[1, 0].scatter(x, y)
111113
axs[0, 0].hist(x)

examples/subplots_axes_and_figures/colorbar_placement.py

Lines 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 numpy as np
1313

14+
15+
# Fixing random state for reproducibility
16+
np.random.seed(19680801)
17+
1418
fig, axs = plt.subplots(2, 2)
1519
cm = ['RdBu_r', 'viridis']
1620
for col in range(2):

examples/subplots_axes_and_figures/subplot_toolbar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11+
12+
# Fixing random state for reproducibility
13+
np.random.seed(19680801)
14+
1115
fig, axs = plt.subplots(2, 2)
1216

1317
axs[0, 0].imshow(np.random.random((100, 100)))

examples/ticks_and_spines/colorbar_tick_labelling_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
from matplotlib import cm
1414
from numpy.random import randn
1515

16+
17+
# Fixing random state for reproducibility
18+
np.random.seed(19680801)
19+
1620
###############################################################################
1721
# Make plot with vertical (default) colorbar
1822

examples/userdemo/annotate_text_arrow.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import numpy as np
99
import matplotlib.pyplot as plt
1010

11+
12+
# Fixing random state for reproducibility
13+
np.random.seed(19680801)
14+
1115
fig, ax = plt.subplots(figsize=(5, 5))
1216
ax.set_aspect(1)
1317

0 commit comments

Comments
 (0)