可视化模拟正弦余弦折线图
import matplotlib.pyplot as pltimport numpy as npplt.rcParams['font.sans-serif'] = ['simhei']plt.rcParams['axes.unicode_minus'] = False#生成模拟数据x = np.arange(0,2*np.pi,0.1)y1 = np.sin(x)y2 = np.cos(x)#创建图形,切分绘图区域,绘制两条曲线plt.figure(num='正弦余弦图')plt.plot(x,y1,label="正弦")plt.plot(x,y2,label="余弦")#设置并显示图例,使用bbox_to_anchor参数使用plt.legend()plt.show()
效果图如下: