Jupyter Snippet CB2nd 03_brownian

Jupyter Snippet CB2nd 03_brownian

13.3. Simulating a Brownian motion

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
n = 5000
x = np.cumsum(np.random.randn(n))
y = np.cumsum(np.random.randn(n))
# We add 10 intermediary points between two
# successive points. We interpolate x and y.
k = 10
x2 = np.interp(np.arange(n * k), np.arange(n) * k, x)
y2 = np.interp(np.arange(n * k), np.arange(n) * k, y)
fig, ax = plt.subplots(1, 1, figsize=(8, 8))
# Now, we draw our points with a gradient of colors.
ax.scatter(x2, y2, c=range(n * k), linewidths=0,
           marker='o', s=3, cmap=plt.cm.jet,)
ax.axis('equal')
ax.set_axis_off()

png