Ma Y
Ma Y

Reputation: 706

Plotting many lines in one figure in Python using two for loops

In the following code Im trying to plot some lines in one plot. the second loop gives a line and the first loop repeats that line with different values, so we have many lines in one plot.

The problem is once the lines are drawn the ending and starting points are connected with straight line to each other. I cannot understand what the problem is.

while True:
        inp  = float(input("PLEASE ENTER VALUE): "))
        if inp==0:
            print('***')
            print('0 Is not acceptable')
            print('***')
        else:
            nu_list=[]
            Un_list=[]
            for tmp in range (2,6):
                for xx in range(1,819):
                         .... some lines of code
                    if inp<0:
                        if lim > 1:
                            pass
                        else:
                            nu_list.append(dfimppara.iloc[xx, 1] * 115)
                            ET_list.append(Un(xx, tmp))
                            plt.plot(nu_list, Un_list)
                    else: 
                        ...#some lines of code

plt.show()

Upvotes: 0

Views: 52

Answers (1)

Sheldore
Sheldore

Reputation: 39052

Try moving the two empty lists inside the tmp for loop.

while True:
    inp  = float(input("PLEASE ENTER VALUE): "))
    if inp==0:
        print('***')
        print('0 Is not acceptable')
        print('***')
    else:
        for tmp in range (2,6):
            nu_list=[]
            Un_list=[]
            for xx in range(1,819):
                     .... some lines of code

Upvotes: 1

Related Questions