记录绘图

常见的绘图模板,各种字体的调整都在代码中。

from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']
import matplotlib.pyplot as plt
# from matplotlib import rcParams

result1 = []
result2 = []
result3 = []
result4 = []
result5 = []
result6 = []
result7 = []
result8 = []

with open('0.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result1.append(float(value_list[0]))
        except:
            pass

with open('1.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result2.append(float(value_list[0]))
        except:
            pass

with open('2.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result3.append(float(value_list[0]))
        except:
            pass

with open('3.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result4.append(float(value_list[0]))
        except:
            pass
with open('4.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result5.append(float(value_list[0]))
        except:
            pass
with open('5.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result6.append(float(value_list[0]))
        except:
            pass
with open('6.txt', 'r') as f:#1
    lines = f.readlines()#2
    for line in lines:#3
        line = line.split(':')[1]
        try:
            if line:
                value_list = line.split(',')
                # print(value_list)
                # X.append(int(value[0]))
                result7.append(float(value_list[0]))
        except:
            pass


fig, ax = plt.subplots()
x = []
for i in range(300):
    x.append(i+1)

# 标签参数设置
# params = {
#     'font.serif':'Times New Roman',
#     # 'figure.dpi': 300,
#     # 'savefig.dpi': 300,
#     'font.size': 240,
# }
# plt.rcParams.update(params)
# 曲线参数设置
line_width = 5   # 线宽
plt.plot(x[:300], result1[:300], '#1f77b4', label='0', linewidth=line_width)
plt.plot(x[:300], result2[:300], '#ff7f0e', label='1', linewidth=line_width)
plt.plot(x[:300], result3[:300], '#2ca02c', label='2', linewidth=line_width)
plt.plot(x[:300], result4[:300], '#9467bd', label='3', linewidth=line_width)
plt.plot(x[:300], result5[:300], '#8c564b', label='4', linewidth=line_width)
plt.plot(x[:300], result6[:300], '#bcbd22', label='5', linewidth=line_width)
plt.plot(x[:300], result7[:300], '#d62728', label='6', linewidth=line_width)

# plt.legend(loc='best')
plt.legend(prop={'family': 'Times New Roman', 'size': 24})
# plt.title(u"loss", family='Times New Roman', size=22)
plt.xlabel(u'训练次数', family='sans-serif', size=18)
plt.ylabel(u'损失值', family='sans-serif', fontsize=18)
# plt.xlabel(u'Epochs', family='Times New Roman', size=20)
# plt.ylabel(u'Loss', family='Times New Roman', fontsize=20)
plt.yticks(fontproperties='Times New Roman', size=16)
plt.xticks(fontproperties='Times New Roman', size=16)
plt.xlim(0, 300)
plt.ylim(0, 20)
plt.show()
fig.savefig('./scatter.jpg', dpi=600, format='jpg')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值