引包
import numpy as np
import matplotlib.pyplot as plt
操作一
#x,y轴数据
x=np.linspace(0,5*np.pi,1000)
y1=np.sin(x)
y2=np.sin(x*2)
fig=plt.figure()
# ax=fig.add_subplot(111)
# ax.plot(x,y1)
ax=plt.gca()#获取坐标轴
ax.fill(x,y1,'r',alpha=0.5)#填充颜色
ax.fill(x,y2,'b',alpha=0.5)
plt.show()
操作二
x=np.linspace(0,5*np.pi,1000)
y1=np.sin(x)
y2=np.sin(x*2)
fig=plt.figure()
# ax=fig.add_subplot(111)
ax=plt.gca()
ax.plot(x,y1,x,y2,c='black')#画出线条
ax.fill_between(x,y1,y2,where=y1>y2,facecolor='b',alpha=0.5,interpolate=True)
#填充两线之间的部分 判断 颜色 透明度 是否填充
ax.fill_between(x,y1,y2,where=y2>y1,facecolor='y',alpha=0.5,interpolate=True)
plt.show()