![]()
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = 'SimHei' # 将字体改为中文
plt.rcParams['axes.unicode_minus'] = False # 设置了中文字体默认后,坐标的"-"号无法显示,设置这个参数就可以避免
#生成随机数列
n = 24
y1 = np.random.randint(20,30,n)
y2 = np.random.randint(10,20,n)
#绘制折线图
plt.plot(y1,label = '折线1')
plt.plot(y2,label = '折线2') # x可省略,y不能省略
plt.legend() # 没有这个label出不来
#图的其他信息
plt.title('折线图示例1',fontsize = 20)
plt.xlim(-1,25) # x坐标轴的范围
plt.ylim(0,30) # y坐标轴的范围
plt.xlabel('横坐标x') # 坐标轴标注
plt.ylabel('纵坐标y')
plt.show()
![]()