I am trying to plot a random walk constrained to move about a lattice.
To implement this constraint I am using hstack to format the segments for LineCollection from the matplotlib module.
I want four random walks to start in four quadrants all on the same plot. As my code stands now, I get four individual plots.
How do I specify ploting all the data on the same plot? #multiple 2D random walks
from matplotlib import collections as mc
import numpy as np
import pylab as plt
steps = 1000
coar = np.empty([steps,2],int)
#random walk start cooridiates
n1=np.array([50,50],int)
n2=np.array([-50,50],int)
n3=np.array([-50,-50],int)
n4=np.array([50,-50],int)
na = [n1,n2,n3,n4]
#colors of the four random walks
clr = ['g','c','m','y']
with open("raw_ran_576001.txt","r") as rf:
for j in range(len(na)):
for t in range(0,steps):
bin=rf.read(2) #reads two bits to generate random step of walk
if(bin=="00"):
na[j][0]+=1
elif(bin=="11"):
na[j][0]-=1
elif(bin=="01"):
na[j][1]+=1
elif(bin=="10"):
na[j][1]-=1
coar[t] = na[j]
coart = coar.reshape(-1,1,2)
segments = np.hstack([coart[:-1],coart[1:]])
# figure out how to add different random walks in different colors
#to same plot
coll = mc.LineCollection(segments,color=clr[j])
fig, ax=plt.subplots() #just a figure and one subplot
ax.set_axis_bgcolor('black')
ax.add_collection(coll) #this must be where points are ploted
ax.autoscale()
t=0
plt.show()
What am I overlooking
btw I am using random bits generated from a radioisotope hardware random number generator.