Python 绘图与可视化 matplotlib 填充fill和fill_between

python

参考链接:https://blog.csdn.net/You_are_my_dream/article/details/53457960

fill()填充函数曲线与坐标轴之间的区域:

x = np.linspace(0, 5 * np.pi, 1000)

y1 = np.sin(x)

y2 = np.sin(2 * x)

plt.fill(x, y1, color = "g", alpha = 0.3)

fill_between()填充两个函数曲线之间的部分:

def wave_curve():

n=256

X=np.linspace(-np.pi,np.pi,n,endpoint=True)

Y=np.sin(2*X)

plt.plot(X,Y+1,color='blue',alpha=0.5)

plt.fill_between(X,1,Y+1,color='blue',alpha=.25)#填充两个函数之间的区域,本例中填充(0和Y+1之间的区域)

# plt.fill(Y,X,color='blue')

plt.plot(X,Y-1,color='gray',alpha=0.6)

plt.fill_between(X,-1,Y-1,where=-1>Y-1,color='blue',alpha=.6)

plt.fill_between(X,-1,Y-1,where=-1<Y+1,color='red',alpha=.7)

plt.xlim(-np.pi,np.pi)

plt.xticks([])#为空不显示坐标

plt.ylim(-2.0,2.0)

plt.yticks([])

plt.show()

  效果:

以上是 Python 绘图与可视化 matplotlib 填充fill和fill_between 的全部内容, 来源链接: utcz.com/z/389038.html

回到顶部