I am trying to run a for loop that cycles through colours for each iteration of a for loop. I am finding similar questions that cycle through colours but not one that is dependent on a particular for loop. I provide some links below:
How to pick a new color for each plotted line within a figure in matplotlib?
My code is for a simple random walk
# Parameters
ntraj=10
n=20
p=0.4
# Initialize holder for trajectories
xtraj=np.zeros(n+1,float)
# Simulation
for j in range(ntraj):
for i in range(n):
xtraj[i+1]=xtraj[i]+2.0*np.random.binomial(1,p)-1.0
plt.plot(range(n+1),xtraj,'b-',alpha=0.2)
plt.title("Simple Random Walk")
I would like to create a line with a different colour for each j
. I apologize if the answer is obvious. I am a novice at python.