matplotlib绘制sin、cos曲线

import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']#用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False#用来正常显示负号

x = np.linspace(0, 10, 1000)
y = np.sin(x) + 1
z = np.cos(x ** 2) + 1

plt.figure(figsize = (8, 4))
plt.plot(x,y,label='$\sin x+1$', color = 'red', linewidth = 2)
plt.plot(x,z,'b--',label='$\cos x^2+1$')
plt.xlabel('Time(s)')
plt.ylabel('Volt')
plt.title('A Sample Example')
plt.ylim(0,2.2)
plt.xlim(0,10)
plt.legend(loc='best')

matplotlib绘制sin、cos曲线_第1张图片

你可能感兴趣的:(matplotlib,可视化)