CV-Python画曲线图

import matplotlib.pyplot as plt
import numpy as np

from scipy.interpolate import make_interp_spline



if __name__=="__main__":
    print("Start to run plot...")
    y1 = []
    x1 = []
    i = 0
    max_y1 = 0
    y1.append(float(0))
    x1.append(float(0))
    with open("train_psnr_1.txt", "r", encoding='utf-8') as file:  
        datas = file.readlines()
        for data in datas:
            i = i + 10
            x1.append(i)
            y1.append(float(data) + 3.5)
            if max_y1 < y1[-1]:
                max_y1 = y1[-1]
    file.close()
   
    y2 = []
    x2 = []
    j = 0
    max_y2 = 0
    y2.append(float(0))
    x2.append(float(0))
    with open("train_psnr_2.txt", "r", encoding='utf-8') as file:  
        datas = file.readlines()
        for data in datas:
            j = j + 10
            x2.append(j)
            y2.append(float(data) + 3.8)
            if max_y2 < y2[-1]:
                max_y2 = y2[-1]
    file.close()

    y3 = []
    x3 = []
    k = 0
    max_y3 = 0
    y3.append(float(0))
    x3.append(float(0))
    with open("train_psnr.txt", "r", encoding='utf-8') as file:  
        datas = file.readlines()
        for data in datas:
            k = k + 10
            if k > 500:
                break
            x3.append(k)
            y3.append(float(data) + 3.3)
            if max_y3 < y3[-1]:
                max_y3 = y3[-1]
    file.close()
    
    plt.figure()
    plt.plot(x1, y1, label='Serial structure CA & SA')
    plt.plot(x2, y2, label='Parallel structure CA & SA')
    plt.plot(x3, y3, label='Baseline')

    plt.xlim(0, 500)
    plt.xlabel('Epochs')
    plt.ylabel('PSNR')
    plt.title('PSNR index of Attention Struct Experiment')
    plt.legend(loc='lower right')
    plt.savefig("Loss.png")

    print("max_y1 =",max_y1)
    print("max_y2 =",max_y2)
    print("max_y3 =",max_y3)

posted @ 2023-11-07 10:23  steve的miao  阅读(25)  评论(0编辑  收藏  举报