plt将tensorboard几张loss图合为一张的代码

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
from matplotlib.font_manager import FontProperties
import csv

'''读取csv文件'''

def readcsv(files):
    csvfile = open(files, 'r')
    plots = csv.reader(csvfile, delimiter=',')
    x = []
    y = []
    for row in plots:
        y.append(float(row[2]))
        x.append(float(row[1]))
    return x, y

mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'NSimSun,Times New Roman'

plt.figure()
x2, y2 = readcsv("./g_loss.csv")
plt.plot(x2, y2, color='darkorange', label='g_loss')
# plt.plot(x2, y2, '.', color='red')

# x, y = readcsv("dloss.csv")
# plt.plot(x, y, 'g', label='Without BN')
#
# x1, y1 = readcsv("gloss.csv")
# plt.plot(x1, y1, color='black', label='Without DW and PW')

x4, y4 = readcsv("./d_loss.csv")
plt.plot(x4, y4, color='mediumblue', label='d_loss', linestyle='dashed')

plt.xticks(fontsize=16)
plt.yticks(fontsize=16)

plt.ylim(0, 40)
plt.xlim(0, 18000)


#设置横纵坐标的名称以及对应字体格式
font2 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 20,
}
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=20)    # matplotlib内无中文字节码,需要自行手动添加
plt.xlabel('训练次数',  font2, fontproperties=font_set)
plt.ylabel('loss值',  font2, fontproperties=font_set)

#设置图例并且设置图例的字体及大小
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 23,
}
plt.legend(fontsize=16, prop=font1)

# 设置汉字显示正确
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
# 设置保存完全的图
plt.tight_layout()
plt.savefig('loss.png')
plt.show()

结果图:

 plt将tensorboard几张loss图合为一张的代码_第1张图片

 

你可能感兴趣的:(code,python,深度学习)