matplotlib - Plotting 3D random walk in Python -
i want plot 3-d random walk in python. similar picture given below. can suggest me tool that. trying use matplotlib getting confused on how it.
have lattice
array of zeros x*y*z
dimensional , holds information random walker has walked, turning 0
to 1
on each (x,y,z)
random walker has stepped.
the following think trying do:
import matplotlib mpl mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot plt import random mpl.rcparams['legend.fontsize'] = 10 fig = plt.figure() ax = fig.gca(projection='3d') xyz = [] cur = [0, 0, 0] _ in xrange(20): axis = random.randrange(0, 3) cur[axis] += random.choice([-1, 1]) xyz.append(cur[:]) x, y, z = zip(*xyz) ax.plot(x, y, z, label='random walk') ax.scatter(x[-1], y[-1], z[-1], c='b', marker='o') # end point ax.legend() plt.show()
this give random walk looking this:
Comments
Post a Comment