我在3D情节中生成随机游走。生成的随机游走的数量等于变量traj。如何在一个情节中绘制它们?我正在寻找类似于'坚持'在MatLab。
有我的代码:
def random_walk_3D(n, traj = 1):
for i in range(traj):
skoki = np.array([[0, 1, 0], [1, 0, 0], [0, -1, 0], [0, 0, 1], [-1, 0, 0], [0, 0, -1]])
losy = np.random.randint(6, size = n)
temp = skoki[losy, :]
x = np.array([[0, 0, 0]])
temp1 = np.concatenate((x, temp), axis = 0)
traj = np.cumsum(temp1, axis = 0)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax = plt.gca()
X, Y, Z = zip(*traj)
ax.plot(X, Y, Z)
ax.scatter(X[-1], Y[-1], Z[-1], c='r', marker='o') #the last point
plt.show()