0%

matplotlib画图

结合注释看吧!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import matplotlib.pyplot as plt
fig = plt.figure()
#参数的意思是画N x N的图,第三个参数用来索引第几张图
ax = fig.add_subplot(1,1,1)
#自定义自己的坐标刻度
ax.set_xticks([0,2,4,6,8,10,12,14,16,18,20])
ax.set_yticks([0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0])
#用点画图,两个list个数当然要相等,注意,list里数字不要有什么引号,我被坑了半天,
#因为echarts画图时,string/float这些可以混用
ax.plot([0,1,2,4,6,8,10,12,14,16,18,20],[0.1162, 0.74,0.86, 0.89,0.91, 0.91,0.92,0.92,0.92,0.93,0.93,0.93])
#多画几条线,会自动区分颜色
ax.plot([0,1,2,4,6,8,10,12,14,16,18,20],[0.1562, 0.79,0.86, 0.90,0.92, 0.93,0.93,0.94,0.94,0.94,0.95,0.95])
#按ax的顺序,给上小标记
plt.legend(('one','two'))
#设置标题
# fig.suptitle('figure title demo', fontsize = 14, fontweight='bold')
# # ax.set_title("axes title")
#设置横纵坐标
ax.set_xlabel("Epoch")
ax.set_ylabel("Test Accuracy")
#保存
plt.savefig('mmlp.png')
plt.savefig('mmlp.pdf')
plt.show()
plt.close()
------------- Thank you for reading -------------

Title - Artist
0:00