Use the matplotlib library to draw two curves in a figure

In model comparison, we need to compare the training accuracy curve and verification accuracy curve in a graph to see if it is overfitting, and matplotlib can easily achieve this requirement.

import matplotlib.pyplot as plt
import numpy as np

data = np.arange(0,1,0.01) #伪造从0到1以0.01为增量的数据
plt.title('my lines example') #写上图题
plt.xlabel('x') #为x轴命名为“x”
plt.ylabel('y') #为y轴命名为“y”
plt.xlim(0,1) #设置x轴的范围为[0,1]
plt.ylim(0,1) #同上
plt.xticks([0,0.2,0.4,0.6,0.8,1]) #设置x轴刻度
plt.yticks([0,0.2,0.4,0.6,0.8,1]) #设置y轴刻度
plt.tick_params(labelsize = 20) #设置刻度字号
plt.plot(data,data**2) #第一个data表示选取data为数据集,第二个是函数,data的平方
plt.plot(data,data) #同上
plt.legend(['y = x^2','y = x^3']) #打出图例
plt.show() #显示图形

The resulting graph is as follows:

insert image description here

Guess you like

Origin blog.csdn.net/weixin_45277161/article/details/131021369