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 0to 1 on each (x,y,z) random walker has stepped.

how can create 3d visual of walk? enter image description here

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:

random walk


Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -