1

I would like to plot n different graphs on the same plot with different color. The problem I got is that I get lines between the different plots, and I don't get random color on the graph. I'm an beginner.

My Plot:

Plot

My Code:

import matplotlib.pyplot as plt 
import random
import numpy

list_y = []
list_x = []
counter = 0

# generate data
for i in range(0,5):
    for p in range(0,10):
        list_y.append(random.uniform(0.9,1.2))
         counter=counter+1
         list_x.append(counter)
         print(list_y)
         print(list_x)
    plt.plot(list_x, list_y,c=numpy.random.rand(3,)) 
    counter = 0

# naming the x axis 
plt.xlabel('x - axis') 
# naming the y axis 
plt.ylabel('y - axis') 

# giving a title to my graph 
plt.title('My first graph!') 

# function to show the plot 
plt.show() 
0

1 Answer 1

1

You just misplaced the initialisations

list_y=[]
list_x=[]

before the line for i in range(0,5): rather than after it, hence finally a plot with the points of all 5 graphs is drawn over the preceding ones.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.