import numpy as np
import matplotlib.pyplot as plt
with open("C:\\Users\\dell\\Desktop\\shujuji.txt","w+")as fd:
with open('C:\\Users\\dell\\Desktop\\accuracy.txt', 'r') as fa: #############需输入y1.txt地址
with open('C:\\Users\\dell\\Desktop\\top1.txt', 'r') as fb: #############需输入y2.txt地址
with open('C:\\Users\\dell\\Desktop\\top5.txt', 'r') as fc: #############需输入y3.txt地址
i=0
for line in fa:
i=i+1
linea=line.strip('\r\n')
lineb=fb.readline()
linec=fc.readline()
fd.write(str(i)+" "+linea+" "+lineb.strip('\r\n')+" "+linec.strip('\r\n'))
fd.write("\n")
#######################合并 y1 y2 y3 ######################
x = []
y1 = []
y2 = []
y3 = []
with open("C:\\Users\\dell\\Desktop\\shujuji.txt","r")as fd:
for line in fd:
line = line.strip('\n')
line = line.split(' ')
x.append(float(line[0]))
y1.append(float(line[1]))
y2.append(float(line[2]))
y3.append(float(line[3]))
###################### txt转变为数组 ######################
plt.plot(x,y1,c='royalblue', label="current")
plt.plot(x,y2,c='coral',label="top1")
plt.plot(x,y3,c='black',label="top5") # 画线
plt.scatter(x,y1,c='royalblue')
plt.scatter(x,y2,c='coral')
plt.scatter(x,y3,c='black') # 画点
plt.legend(loc='best',frameon=False) # 图例边框
plt.xticks(range(0, 21, 1))
plt.yticks(range(0, 110,10))# x,y轴刻度
plt.xlabel("Epoch", fontdict={'size': 16})
plt.ylabel("Percentage%", fontdict={'size': 16})
plt.title("评价标准图", fontdict={'size': 20})
plt.show()
###################### 作图 ######################
2.折线图
于 2022-06-15 21:43:07 首次发布
该博客内容涉及将三个数据文件'y1.txt'、'y2.txt'和'y3.txt'的内容合并成一个新的数据文件,并利用numpy和matplotlib库绘制了关于'current'、'top1'和'top5'的评价标准曲线图。图表清晰展示了随着Epoch(周期)增加,各项指标的变化趋势,用于评估模型性能。
摘要由CSDN通过智能技术生成