Я хочу нарисовать случайный путь процесса из начала (0,0), который обновляется шаг за шагом. Я использовал анимацию matplotlib, но она рисует простую линию. Как нарисовать путь?
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
# Process simulation (Wiener process)
n = 1000
sd = np.sqrt(0.1)
w = np.zeros(n)
for i in range(n-1):
w[i+1] = w[i] + np.random.normal(0, sd)
# Set up the figure, the axis, and the plot element to animate
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_xlim([0, 1000])
ax.set_ylim([-50, 50])
th = np.linspace(0., n, n / 0.1, endpoint=False)
line, = ax.plot([],[],'b-', animated=True)
line.set_xdata(th)
# Animation function
def update(data):
line.set_ydata(data)
return line,
def data_gen():
t = -1
while True:
t +=1
yield w[t]
# Call the animation
anim = animation.FuncAnimation(fig, update, data_gen, interval=10, blit=True)
plt.show()