读取txt文件中的数据并绘制折线图(log)

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import PIL.Image as Img
import os
import pickle
import xml.etree.ElementTree as ET
from xml.etree.ElementTree import ElementTree, Element
import matplotlib.pyplot as plt
import time

data_dir = 'jueyuanzi.txt'
f1 = open(data_dir, 'r', encoding='utf-8')
x = []
y = []
y1 = []
for line in f1:
    line = line.split()
    if 'jueyuanzi_01' in line and 'accuracy' in line[4]:
        #print(line[4].split(':')[1])
        y.append(float(line[4].split(':')[1]))
    if 'jueyuanzi_02' in line and 'accuracy' in line[4]:
        #print(line[4].split(':')[1])
        y1.append(float(line[4].split(':')[1]))
    if 'Start' in line and 'Epoch' in line and int(line[5]) % 5 == 0 and line[5] != '5' and int(line[5])>=50:
        # print(int(line[5]))
        x.append(int(line[5]))

plt.plot(x, y, label='jueyuanzi_01')
plt.plot(x, y1, label='jueyuanzi_02')
plt.legend(loc='best')
# plt.xlabel('Epoch')
plt.show()

猜你喜欢

转载自blog.csdn.net/qq_33193309/article/details/104948038