博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
matplotlib 画曲线图2
阅读量:4210 次
发布时间:2019-05-26

本文共 1850 字,大约阅读时间需要 6 分钟。

import matplotlib.pyplot as pltimport numpy as npdef get_file(acc_list,loss_list,filename):    f1 = open(filename, 'r')    for line in f1.readlines():        # print(line)        line = line.strip('\n')        str_list = line.split(':')        loss = float(str_list[-2].split(',')[0])        acc = float(str_list[-1])        acc_list.append(acc)        loss_list.append(loss)baseline_acc=[]baseline_loss=[]dgc_acc=[]dgc_loss=[]ip_acc=[]ip_loss=[]rand_4_dgc_acc=[]rand_4_dgc_loss=[]# 获取acc,loss数据get_file(baseline_acc,baseline_loss,'train_baseline_resnet50.txt')get_file(dgc_acc,dgc_loss,'train_dgc_resnet50.txt')get_file(ip_acc,ip_loss,'train_ip_resnet50.txt')get_file(rand_4_dgc_acc,rand_4_dgc_loss,'train_rand_4_dgc_resnet50.txt')plt.figure()# 横坐标轴x = [i for i in range(0,88)]# 在绘制时设置lable, 逗号是必须的# l1, = plt.plot(x, baseline_loss[0:88], label = 'line', color = 'b', linewidth = 1.0, linestyle = '-')# l2, = plt.plot(x, dgc_loss[2:90], label = 'line', color = 'g', linewidth = 1.0, linestyle = '-')# l3, = plt.plot(x, ip_loss[2:90], label = 'line', color = 'r', linewidth = 1.0, linestyle = '-')# l4, = plt.plot(x, rand_4_dgc_loss[2:90], label = 'line', color = 'c', linewidth = 1.0, linestyle = '-')l1, = plt.plot(x, baseline_acc[0:88], label = 'line', color = 'b', linewidth = 1.0, linestyle = '-')l2, = plt.plot(x, dgc_acc[2:90], label = 'line', color = 'g', linewidth = 1.0, linestyle = '-')l3, = plt.plot(x, ip_acc[2:90], label = 'line', color = 'r', linewidth = 1.0, linestyle = '-')l4, = plt.plot(x, rand_4_dgc_acc[2:90], label = 'line', color = 'c', linewidth = 1.0, linestyle = '-')# 设置坐标轴的lableplt.xlabel('epoch')# plt.ylabel('loss')plt.ylabel('accuracy')# 设置legendplt.legend(handles = [l1, l2, l3,l4], labels = ['baseline', 'dgc','ip','rand_4_dgc'], loc = 'best')plt.grid()# plt.show()# plt.savefig('loss.jpg')plt.savefig('accuracy.jpg')

在这里插入图片描述

转载地址:http://xfwmi.baihongyu.com/

你可能感兴趣的文章
15丨性能测试场景:如何进行监控设计
查看>>
16丨案例:性能监控工具之Grafana-Prometheus-Exporters
查看>>
九度OJ 1085:求root(N, k) (迭代)
查看>>
九度OJ 1086:最小花费 (DP)
查看>>
九度OJ 1087:约数的个数 (数字特性)
查看>>
九度OJ 1088:剩下的树 (线段树)
查看>>
九度OJ 1089:数字反转 (数字反转)
查看>>
九度OJ 1090:路径打印 (树、DFS)
查看>>
九度OJ 1091:棋盘游戏 (DP、BFS、DFS、剪枝)
查看>>
九度OJ 1092:Fibonacci (递归)
查看>>
九度OJ 1093:WERTYU (翻译)
查看>>
九度OJ 1094:String Matching(字符串匹配) (计数)
查看>>
九度OJ 1095:2的幂次方 (递归)
查看>>
九度OJ 1471-1480(10/10)
查看>>
九度OJ 1481-1490(7/10)
查看>>
九度OJ 1491-1500(5/10)
查看>>
九度OJ 1501-1510(10/10)
查看>>
业务系统中,报表统计功能如何组织--统计分析模块参考
查看>>
面向数据集成的ETL技术研究
查看>>
DataStage(ETL)技术总结 -- 介绍篇(转载)
查看>>