Graphics and Visualization Python matplotlib fill and fill fill_between

Reference link: https: //blog.csdn.net/You_are_my_dream/article/details/53457960

fill () function to fill the area between the curve and the coordinate axes:

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 () partially filled between two curves function:

wave_curve DEF (): 
    n-= 256 
    X-np.linspace = (-np.pi, np.pi, n-, Endpoint = True) 
    the Y np.sin = (X-2 *) 

    plt.plot (X-, the Y +. 1, Color = 'Blue', Alpha = 0.5) 
    # fill the region between the two functions plt.fill_between (X, 1, Y + 1, color = 'blue', alpha = .25), the present embodiment is filled (0 and Y region between + 1'd) 
    # plt.fill (the Y, X-, Color = 'Blue') 

    plt.plot (X-, the Y-. 1, Color = 'Gray', Alpha = 0.6) 
    plt.fill_between (X-, -1 , the Y-. 1, WHERE = -1>. 1 the Y-, Color = 'Blue', Alpha = .6) 
    plt.fill_between (X-, -1, the Y-. 1, -1 = WHERE <+. 1 the Y, Color = ' Red ', Alpha = .7) 
    
    plt.xlim (-np.pi, np.pi) 
    plt.xticks ([]) is not empty display coordinate # 
    plt.ylim (-2.0,2.0) 
    plt.yticks ([]) 
    
    plt.show ()

  effect:

 

Guess you like

Origin www.cnblogs.com/Gaoqiking/p/11069517.html