CV-Python画曲线图

发布时间 2023-11-07 10:26:54作者: starc再起航
import matplotlib.pyplot as plt
import numpy as np

from scipy.interpolate import make_interp_spline





def readLoss(path, x, y):
    i = 0
    y.append(float(0))
    x.append(float(0))
    with open(path, "r", encoding='utf-8') as file:  
        datas = file.readlines()
        for data in datas:
            i = i + 1
            x.append(i)
            y.append(float(data))

    #x = np.array(x)
    #y = np.array(y)
    file.close()
    #return x, y




if __name__=="__main__":
    print("asd")
    y1 = []
    x1 = []
    #x1, y1 = readLoss("DPF.txt", x1, y1)
    i = 0
    y1.append(float(0))
    x1.append(float(0))
    with open("DPF.txt", "r", encoding='utf-8') as file:  
        datas = file.readlines()
        for data in datas:
            i = i + 1
            x1.append(i)
            y1.append(float(data))
    file.close()
   
    y2 = []
    x2 = []
    x2, y2 = readLoss("DPF-DWT-50.txt", x2, y2)

    y3 = []
    x3 = []
    x3, y3 = readLoss("DPF-perc-L1.txt", x3, y3)

    y4 = []
    x4 = []
    x4, y4 = readLoss("DPF-perc-ssim-L1.txt", x4, y4)
    
    plt.figure()
    plt.plot(x1, y1, label='DPF')
    plt.plot(x2, y2, label='DPF-DWT-50')
    plt.plot(x3, y3, label='DPF-perc-L1')
    plt.plot(x4, y4, label='DPF-perc-ssim-L1')

    plt.xlabel('Epochs')
    plt.ylabel('PSNR')
    plt.title('Loss Function Comparison')
    plt.legend()
    plt.savefig("Loss.png")


    
    #x = np.array(x)
    #y = np.array(y)
    #X_Y_Spline = make_interp_spline(x, y)
    #X_ = np.linspace(x.min(), x.max(), 100)
    #Y_ = X_Y_Spline(X_)

    #plt.xlim(0, 50)
    #plt.ylim(17, 22)