一穷二白学Matplotlib,作第一张图

注意事项

  1. figure()实现用一个脚本画多幅图
  2. plt.legend() 如果在一个图像中作了多条曲线,则在右上角显示图例
  3. plt.plot(X, train_loss, color=‘green’, label=‘train_loss’)
    即作图(横轴,纵轴,颜色,标签(用plt.legend()可以显示图例))
  4. plt.xlabel(‘横轴含义’) plt.ylabel(‘纵轴含义’)
  5. plt.show()最终显示图

重要代码

filename = 'C:/Users/qinan/Desktop/log.txt'
X,train_loss,valid_loss,train_acc, valid_acc = [],[],[],[],[]
with open(filename, 'r')as f: #1
    lines = f.readlines()  #2
    x = len(lines)

    for line in lines:    #3
        value = [float(s) for s in line.split()]   #4
        # X.append(value[0])  #5
        train_loss.append(value[1])

代码

# coding=utf-8            # 为了正确打印汉字
# @author:Eagle
# @time: 2019/09/04


import matplotlib.pyplot as plt
filename = 'C:/Users/qinan/Desktop/log.txt'
X,train_loss,valid_loss,train_acc, valid_acc = [],[],[],[],[]
with open(filename, 'r')as f: #1
    lines = f.readlines()  #2
    x = len(lines)

    for line in lines:    
        value = [float(s) for s in line.split()]  
        train_loss.append(value[1])
        valid_loss.append(value[2])
        train_acc.append(value[3])
        valid_acc.append(value[4])

X = [i for i in range(x)]
print(X)
print(train_loss)
print(valid_loss)

plt.figure()
plt.plot(X, train_loss, color='green', label='train_loss')
plt.plot(X,valid_loss,color='red', label='valid_loss')

plt.title('test')
plt.xlabel('epoch')
plt.ylabel('loss')

plt.figure()
plt.plot(X, train_acc, color='blue', label='train_acc')
plt.plot(X,valid_acc,color='pink', label='valid_acc')

plt.title('test')
plt.xlabel('epoch')
plt.ylabel('acc')



plt.legend()
plt.show()

最终效果

在这里插入图片描述
在这里插入图片描述

数据

0.100000	2.261275	1.931926	15.066000	23.420000	
0.100000	1.806991	1.605883	31.508000	39.970000	
0.100000	1.563165	1.522051	42.168000	44.520000	
0.100000	1.349931	1.438414	50.748000	51.650000	
0.100000	1.166912	1.098071	58.180000	61.110000	
0.100000	1.018413	1.039381	63.756000	62.960000	
0.100000	0.913306	0.881787	67.776000	69.790000	
0.100000	0.833747	0.841285	70.418000	71.390000	
0.100000	0.754350	0.949823	73.442000	68.450000	
0.100000	0.681121	0.965223	76.348000	68.470000	
0.100000	0.622720	0.731599	78.364000	75.960000	
0.100000	0.576068	0.662935	80.074000	77.810000	
0.100000	0.542148	0.623652	81.366000	78.810000	
0.100000	0.508195	0.642450	82.392000	78.230000	
0.100000	0.482408	0.529790	83.492000	82.650000	
0.100000	0.451166	0.594648	84.536000	80.320000	
0.100000	0.437965	0.664356	84.790000	78.940000	
0.100000	0.411453	0.546932	85.624000	81.590000	
0.100000	0.402840	0.497517	86.028000	83.630000	
0.100000	0.384014	0.534307	86.762000	83.170000	
0.100000	0.368189	0.574291	87.260000	81.270000	
0.100000	0.356464	0.507068	87.620000	83.120000	
0.100000	0.343836	0.614259	88.042000	81.260000	
0.100000	0.333800	0.623832	88.456000	80.780000	
0.100000	0.327621	0.471152	88.728000	84.490000	
0.100000	0.314796	0.518815	89.028000	83.100000	
0.100000	0.306022	0.431247	89.220000	86.130000	
0.100000	0.301972	0.437085	89.592000	85.670000	
0.100000	0.293747	0.661031	89.800000	81.000000	
0.100000	0.285976	0.438094	90.090000	86.040000	
0.100000	0.279040	0.463431	90.186000	85.480000	
0.100000	0.269380	0.464273	90.810000	85.350000	
0.100000	0.264131	0.573648	90.906000	82.990000	
0.100000	0.263346	0.749618	90.830000	79.420000	
0.100000	0.258816	0.458356	90.912000	85.420000	
0.100000	0.247003	0.550276	91.368000	83.620000	
0.100000	0.247969	0.413072	91.314000	87.400000	
0.100000	0.240642	0.424444	91.666000	86.280000	
0.100000	0.238169	0.436849	91.654000	86.470000	
0.100000	0.234862	0.508181	91.768000	84.850000	
0.100000	0.235736	0.470564	91.836000	85.550000	
0.100000	0.225426	0.415698	92.178000	87.030000	
0.100000	0.230107	0.490622	91.892000	85.270000	
0.100000	0.230684	0.393610	91.980000	87.510000	
0.100000	0.220006	0.464247	92.392000	85.600000	
0.100000	0.213353	0.453993	92.590000	86.320000	
0.100000	0.213351	0.383766	92.546000	87.750000	
0.100000	0.218396	0.531175	92.342000	84.580000	
0.100000	0.205302	0.410727	92.846000	87.530000	
0.100000	0.208175	0.387916	92.766000	87.400000	
0.100000	0.205338	0.590296	92.704000	83.710000	
0.100000	0.199095	0.482088	93.072000	85.360000	
0.100000	0.202025	0.371466	93.008000	88.560000	
0.100000	0.202325	0.377094	92.880000	88.390000	
0.100000	0.193275	0.435942	93.296000	86.850000	
0.100000	0.195891	0.375586	93.178000	88.330000	
0.100000	0.194107	0.542851	93.148000	84.270000	
0.100000	0.188302	0.429969	93.412000	87.720000	
0.100000	0.190469	0.438546	93.438000	86.870000	
0.100000	0.186354	0.472317	93.498000	86.000000	
0.100000	0.183397	0.382676	93.520000	88.230000	
0.100000	0.182237	0.350691	93.550000	88.760000	
0.100000	0.186485	0.408130	93.482000	87.660000	
0.100000	0.184856	0.467288	93.570000	86.620000	
0.100000	0.184977	0.412049	93.522000	88.050000	
0.100000	0.181795	0.382106	93.658000	88.770000	
0.100000	0.179164	0.522996	93.724000	84.940000	
0.100000	0.178604	0.426808	93.738000	87.110000	
0.100000	0.174790	0.648510	93.842000	82.720000	
0.100000	0.169771	0.464722	94.080000	86.820000	
0.100000	0.168411	0.430138	94.144000	87.670000	
0.100000	0.173488	0.463653	94.050000	86.670000	
0.100000	0.170211	0.406734	94.034000	88.180000	
0.100000	0.169295	0.349600	94.060000	89.270000	
0.100000	0.173900	0.527497	93.854000	84.930000	
0.100000	0.169873	0.358659	94.084000	88.900000	
0.100000	0.167105	0.372480	94.140000	88.590000	
0.100000	0.163507	0.389080	94.174000	88.770000	
0.100000	0.164727	0.505060	94.252000	85.460000	
0.100000	0.159524	0.456416	94.450000	86.990000	
0.100000	0.161950	0.423436	94.266000	87.820000	
0.010000	0.080396	0.252979	97.298000	92.600000	
0.010000	0.051080	0.250180	98.362000	92.920000	
0.010000	0.040415	0.256070	98.716000	93.060000	
0.010000	0.035354	0.261544	98.848000	93.020000	
0.010000	0.029887	0.267328	99.094000	93.110000	
0.010000	0.026960	0.274449	99.184000	93.150000	
0.010000	0.024180	0.272201	99.238000	93.330000	
0.010000	0.020529	0.275613	99.396000	93.390000	
0.010000	0.019630	0.279534	99.424000	93.140000	
0.010000	0.017569	0.282840	99.482000	93.210000	
0.010000	0.016702	0.285848	99.528000	93.260000	
0.010000	0.015806	0.291081	99.528000	93.310000	
0.010000	0.014058	0.298896	99.586000	93.310000	
0.010000	0.012473	0.303316	99.632000	93.440000	
0.010000	0.012340	0.299223	99.662000	93.480000	
0.010000	0.011414	0.310941	99.650000	93.330000	
0.010000	0.010427	0.307078	99.718000	93.470000	
0.010000	0.010757	0.315220	99.702000	93.360000	
0.010000	0.010405	0.311173	99.692000	93.360000	
0.010000	0.009296	0.312502	99.748000	93.540000	
0.010000	0.009395	0.319555	99.744000	93.270000	
0.010000	0.009464	0.321257	99.708000	93.360000	
0.010000	0.009210	0.319542	99.732000	93.260000	
0.010000	0.007547	0.321393	99.794000	93.400000	
0.010000	0.007597	0.334132	99.770000	93.240000	
0.010000	0.007377	0.332571	99.798000	93.280000	
0.010000	0.007628	0.338312	99.782000	93.230000	
0.010000	0.006466	0.339655	99.822000	93.350000	
0.010000	0.006745	0.339340	99.834000	93.290000	
0.010000	0.006436	0.342719	99.824000	93.240000	
0.010000	0.005748	0.336880	99.852000	93.140000	
0.010000	0.005971	0.348829	99.834000	93.080000	
0.010000	0.005962	0.342977	99.838000	93.140000	
0.010000	0.005865	0.355096	99.834000	93.140000	
0.010000	0.005769	0.347570	99.852000	93.100000	
0.010000	0.006127	0.348756	99.822000	93.090000	
0.010000	0.005922	0.349157	99.850000	93.150000	
0.010000	0.005166	0.346819	99.858000	93.430000	
0.010000	0.004776	0.349911	99.862000	93.170000	
0.010000	0.004991	0.349211	99.866000	93.230000	
0.010000	0.005958	0.348244	99.836000	93.230000	
0.001000	0.004572	0.342603	99.888000	93.380000	
0.001000	0.004028	0.341506	99.916000	93.350000	
0.001000	0.003656	0.339686	99.914000	93.340000	
0.001000	0.003620	0.337736	99.920000	93.440000	
0.001000	0.003693	0.337933	99.906000	93.350000	
0.001000	0.003432	0.337759	99.928000	93.480000	
0.001000	0.003406	0.340996	99.916000	93.430000	
0.001000	0.003482	0.336761	99.938000	93.390000	
0.001000	0.003295	0.336401	99.932000	93.440000	
0.001000	0.002842	0.339925	99.944000	93.410000	
0.001000	0.003116	0.337688	99.942000	93.480000	
0.001000	0.003408	0.337771	99.920000	93.470000	
0.001000	0.003147	0.340660	99.928000	93.400000	
0.001000	0.002986	0.336786	99.922000	93.610000	
0.001000	0.003121	0.338830	99.920000	93.490000	
0.001000	0.002957	0.339195	99.938000	93.430000	
0.001000	0.002627	0.338042	99.944000	93.530000	
0.001000	0.002870	0.337515	99.938000	93.560000	
0.001000	0.002732	0.340366	99.954000	93.510000	
0.001000	0.002901	0.338308	99.928000	93.590000	
0.001000	0.002790	0.339283	99.950000	93.560000	
0.001000	0.002570	0.341703	99.944000	93.410000	
0.001000	0.002569	0.340715	99.952000	93.420000	
0.001000	0.002933	0.340508	99.934000	93.470000	
0.001000	0.002982	0.343607	99.946000	93.540000	
0.001000	0.002831	0.345630	99.950000	93.510000	
0.001000	0.002651	0.341117	99.940000	93.620000	
0.001000	0.002528	0.339166	99.946000	93.470000	
0.001000	0.002593	0.339576	99.956000	93.440000	
0.001000	0.002744	0.339802	99.944000	93.530000	
0.001000	0.002569	0.343554	99.958000	93.590000	
0.001000	0.002689	0.339147	99.952000	93.520000	
0.001000	0.002623	0.341799	99.952000	93.570000	
0.001000	0.002435	0.341710	99.966000	93.560000	
0.001000	0.002596	0.340075	99.950000	93.520000	
0.001000	0.002582	0.340389	99.954000	93.530000	
0.001000	0.002382	0.338985	99.968000	93.580000	
0.001000	0.002133	0.343907	99.980000	93.570000	
0.001000	0.002426	0.338686	99.964000	93.630000	
0.001000	0.002468	0.342510	99.952000	93.610000	
0.001000	0.002540	0.345946	99.960000	93.610000	
0.001000	0.002051	0.344323	99.972000	93.490000	

参考博客

更多相关推荐

matplotlib 一张图多个图_matplo...

上一节了解了一张画布中只有一个子图绘图方法后,现在来讨论一张画布中有多个子图的绘图实践,...

继续阅读

matplotlib 一张图多个图_Matplo...

我想用matplotlib生成一个多重绘图,并在每个子图的角上嵌入一个图像。在我现在正在尝试在一系...

继续阅读

ArcGIS API for JS 第一张地图

1.由于中美贸易大战,貌似已经无法从官网下载到离线版的js文件。目前只能通过cdn,或者自己下...

继续阅读

一张图了解python_一张图学会pyt...

提到一张图,大多数人都知道,有人问一张图学会python,当然了,还有人问python将多个列表合并...

继续阅读

Python学习笔记(同时纪念自己的...

来自“ITPUB博客”,链接:http://blog.itpub.net/7719012/viewspace-1159471/,如需转载,请注...

继续阅读

Matplotlib:一张图同时展示柱状...

项目中要做数据分析,将客户按照信用卡使用率划分了几段,每段统计好人数,用柱状图展示,并计...

继续阅读

第一张失败的5层全连接网络

第一个5层全连接的网络,输入输出关系符合y=[[x1],[x2]]*[1,1] 矩阵相乘 ,y=x1+x2不过跑出来的...

继续阅读

一张图教你学会python_一张图教...

Python是一个非常适合初学者入门的编程语言。相比较其他不少主流编程语言,有更好的可读性,因...

继续阅读

使用matplotlib在一张图上画多条...

做数据分析,还有机器学习的收敛性,准确性分析时,往往需要将一些数据图形化,以曲线的形式显...

继续阅读