用matplotlib库画图


1、用例一

 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3 x=np.linspace(0,10,100)
 4 y=np.cos(2*np.pi*x)*np.exp(-x)+0.9
 5 plt.plot(x,y,'k',color='b',label="$08$",linewidth=3)
 6 plt.axis([0,6,0,1.8])
 7 ix=(x>0.8)&(x<3)
 8 plt.fill_between(x,y,0,where=ix,\
 9                 facecolor='grey',alpha=0.25)
10 plt.text(0.5*(0.8+3),0.2,r"$\int_a^b f(x)\mathrm{d}x$",\
11          horizontalalignment='center')
12 plt.legend()
13 plt.show()

 

  

 

2、用例二

 1 import matplotlib.pyplot as plt
 2 import numpy as np
 3 x=np.linspace(0,10,100)
 4 y=np.cos(2*np.pi*x)*np.exp(-x)+0.9
 5 plt.plot(x,y,'k',color='b',label="$08$",linewidth=3)
 6 #plt.axis([0,6,0,1.8])
 7 #ix=(x>0.8)&(x<3)
 8 #plt.fill_between(x,y,0,where=ix,\
 9 #                facecolor='grey',alpha=0.25)
10 #plt.text(0.5*(0.8+3),0.2,r"$\int_a^b f(x)\mathrm{d}x$",\
11         # horizontalalignment='center')
12 plt.legend()
13 plt.show()

 

  

 


作者:一枚小可爱,发布于:2019/04/15
原文:https://www.cnblogs.com/sun0618-/p/10710983.html