Table of contents
1.1 Filling of the area under the curve
1.3 Area filling between two curves
1. Filling of the drawing
The filling of the drawing can be filled by calling fill_between() or fill().
1.1 Filling of the area under the curve
x = np.linspace(0,1,500)
y = np.sin(3*np.pi*x)*np.exp(-4*x)
fig,ax = plt.subplots()
plt.plot(x,y)
plt.fill_between(x,-0.1, y, facecolor = 'green', alpha = 0.3)
In the last line of the code, the parameter x indicates that the entire X-axis is covered, 0 indicates the lower limit of coverage, y indicates that the upper limit of coverage is the curve of y, facecolor indicates the color of the fill, and alpha indicates the opacity of the covered area.
result:
1.2 Fill part of the area
x = np.linspace(0,1,500)
y = np.sin(3*np.pi*x)*np.exp(-4*x)
fig,ax = plt.subplots()
plt.plot(x,y)
plt.fill_between(x[15:300], 0, 0.4, facecolor = 'blue', alpha = 0.3)
result:
1.3 Area filling between two curves
x = np.linspace(0,1,500)
y1 = np.sin(3*np.pi*x)*np.exp(-4*x)
y2 = y1 + 0.2
plt.plot(x, y1,'b')
plt.plot(x, y2, 'r')
plt.fill_between(x, y1, y2, facecolor = 'green', alpha = 0.3)
plt.show()
result:
1.4 Use fill directly to fill
x = np.linspace(0,1,500)
y = np.sin(3*np.pi*x)*np.exp(-4*x)
fig,ax = plt.subplots()
ax.fill(x,y,'yellow')
plt.show()
result: