Last active
April 13, 2020 23:14
-
-
Save IlievskiV/c600db9ee3ae0c47d5e421c3917d0e22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
fig = plt.figure(figsize=(21, 10)) | |
ax = plt.axes(xlim=(0, N), ylim=(np.min(X) - 0.5, np.max(X) + 0.5)) | |
line, = ax.plot([], [], lw=2, color='#0492C2') | |
ax.set_xticks(np.arange(0, N+1, 50)) | |
ax.set_yticks(np.arange(np.min(X) - 0.5, np.max(X) + 0.5, 0.2)) | |
ax.set_title('2D Random Walk', fontsize=22) | |
ax.set_xlabel('Steps', fontsize=18) | |
ax.set_ylabel('Value', fontsize=18) | |
ax.tick_params(labelsize=16) | |
ax.grid(True, which='major', linestyle='--', color='black', alpha=0.4) | |
# initialization function | |
def init(): | |
# creating an empty plot/frame | |
line.set_data([], []) | |
return line, | |
# lists to store x and y axis points | |
xdata, ydata = [], [] | |
# animation function | |
def animate(i): | |
y = X[i] | |
# appending new points to x, y axes points list | |
xdata.append(i) | |
ydata.append(y) | |
line.set_data(xdata, ydata) | |
return line, | |
# call the animator | |
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=N, interval=20, blit=True) | |
anim.save('random_walk.gif',writer='imagemagick') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment