一
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import numpy as np #引用numpy库,从新命名它为np(以后用np代替numpy,简洁) import matplotlib.pyplot as plt import matplotlib x = np.linspace(0,6,100) #在【0,6】平均分为100个 print(x) #输出查看一下x内容 y = np.cos(2*np.pi*x) * np.exp(-x) + 0.8 #调用np库里的cos函数 print(y) #输出Y查看一下内容 plt.plot(x,y,'k',color='r',linewidth=3,linestyle="-") #color='r'代表红色 plt.show() #展示绘图
二
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import numpy as np import matplotlib.pyplot as plt x=np.linspace(0,10,1000) y=np.cos(2*np.pi*x)*np.exp(-x)+0.8 plt.plot(x,y,'k',color='r',label="$exp-decay$",linewidth=3) plt.axis([0,6,0,1.8]) ix=(x>0.8)&(x<3) plt.fill_between(x,y,0,where=ix,facecolor='red',alpha=0.25) plt.text(0.5*(0.8+3),0.2,r"$int_a^b f(x)mathrm{d}x$",horizontalignment='center') plt.legend() plt.show()