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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -