不完整的线图

时间:2017-04-24 00:29:46

标签: matplotlib plot graph line

我正在开发一个应用程序,根据用户的输入绘制图形。但是,当我尝试绘制图表时,该行不会一直存在。

代码如下:

    v = text_v.get()
    i = text_i.get()
    v2 = v.split(", ")
    i2 = i.split(", ")
    outcome = True

    #Testing for pairing of values
    if range(len(v2)) != range(len(i2)):
        tkm.showerror("Incomplete values", "You did not enter an equal number of voltage and resistance values")
        outcome = False

    #Testing for v-value type
    for x in range(len(v2)):
        try:
            float(v2[x])
            outcome = True
        except:
            tkm.showerror("Wrong value type", "All your voltage values must be floats or integers")
            outcome = False
            break

    #Testing for i-value type
    for x in range(len(i2)):
        try:
            float(i2[x])
        except:
            tkm.showerror("Wrong value type", "All your current values must be floats or integers")
            outcome = False
            break

    #------------------------Graph plotting function----------------------------
    if outcome == True:
        v = np.array(list(map(float, v.split(", "))))
        i = np.array(list(map(float, i.split(", "))))
        fit = np.polyfit(i,v,1)
        fit_fn = np.poly1d(fit) 
        plt.plot(i,v, 'bo', v, fit_fn(v), '--k')

0 个答案:

没有答案