I have this code calculating a random walk that I am trying to find the max distance from (0.0) for all walks and add them to a legend. Added an image of the result I want to achieve.
import numpy as np
import matplotlib.pyplot as plt
import math
np.random.seed(12)
repeats = 5
N_steps = 1000000
expected_R = np.sqrt(N_steps)
plt.title(f"{repeats} random walks of {N_steps} steps")
for x in range(repeats):
dirs = np.random.randint(0, 4, N_steps)
steps = np.empty((N_steps, 2))
steps[dirs == 0] = [0, 1] # 0 - right
steps[dirs == 1] = [0, -1] # 1 - left
steps[dirs == 2] = [1, 0] # 2 - up
steps[dirs == 3] = [-1, 0] # 3 - down
steps = steps.cumsum(axis=0)
print("Final position:", steps[-1])
skip = N_steps // 5000 + 1
xs = steps[::skip, 0]
ys = steps[::skip, 1]
x = max(ys)
plt.plot(xs, ys)
circle = plt.Circle((0, 0), radius=expected_R, color="k")
plt.gcf().gca().add_artist(circle)
plt.gcf().gca().set_aspect("equal")
plt.axis([-1500-x,1500+x,-1500-x,1500+x])
plt.show()