[matplotlib library] Use the matplotlib library to draw a python program for sine and cosine function curves, labeling X, Y axes and titles|CSDN creation check-in

Use the third-party library matplotlib in python to draw sine and cosine function graphics, and label x, y axes and titles, etc. The drawing method is similar to matlab. It can be said that the matplotlib library here is matlab in Python

The program code is as follows:

#绘制正余弦函数图像
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family']='SimHei'#配置字体
matplotlib.rcParams['font.sans-serif']=['SimHei']
matplotlib.rcParams['axes.unicode_minus']=False
x1=np.arange(0,4*np.pi,np.pi/10)
y1=np.sin(x1)
y2=np.cos(x1)
plt.figure()
plt.subplot(121)
plt.plot(x1,y1,color='b')
plt.title('正弦函数')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.subplot(122)
plt.plot(x1,y2,color='r')
plt.title('余弦函数')
plt.xlabel('X轴')
plt.ylabel('Y轴')
plt.savefig('正余弦函数.png')
plt.show()

The result of the program running is as follows:

 Finally, don't forget to give the blogger a thumbs up!

Follow bloggers to learn more about Python programming knowledge!

Guess you like

Origin blog.csdn.net/qq_59049513/article/details/122557248