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

参考链接: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

  效果:

Python 绘图与可视化 matplotlib 填充fill和fill_between_第1张图片

 

你可能感兴趣的:(Python 绘图与可视化 matplotlib 填充fill和fill_between)