使用两个for循环在Python中的一个图中绘制多行

时间:2019-11-07 14:48:46

标签: python matplotlib plot

在下面的代码中,我试图在一个图中绘制一些线。第二个循环给出了一条线,第一个循环以不同的值重复了该条线,因此在一个图中我们有很多条线。

问题在于,一旦绘制了直线,终点和起点便以直线相互连接。我不明白是什么问题。

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()

1 个答案:

答案 0 :(得分:1)

尝试在tmp for循环内移动两个空列表。

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