fill_between([0.1,0.3],0.2,0.9,facecolor = 'pink', alpha = 0.9)
第一个参数是X轴范围,需要输入数组;第二个参数是Y轴最小值;第三个参数是Y轴最大值;第四个参数是颜色设置;第五个参数是设置颜色深浅。 举例:
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0,1,500)
y = np.sin(3*np.pi*x)*np.exp(-4*x)+np.cos(x)
fig,ax = plt.subplots()
plt.plot(x,y)
plt.fill_between([0.1,0.3],0.2,0.9,facecolor = 'pink', alpha = 0.9)
举例:
x = np.linspace(0,1,500)
y = np.sin(3*np.pi*x)*np.exp(-4*x)+np.cos(x)
fig,ax = plt.subplots()
plt.plot(x,y)
plt.fill_between([0.1,0.3],0.2,0.9,facecolor = 'pink', alpha = 0.9)
举例: 两函数之间填充
x = np.linspace(0,1,500)
y1 = np.sin(3*np.pi*x)*np.exp(-4*x)+np.cos(x)
y2 = y1 + np.sin(x)
plt.plot(x,y1,'y')
plt.plot(x,y2,'g')
plt.fill_between(x,y1,y2,facecolor = 'blue', alpha = 0.5)
plt.show()
举例:
x = np.linspace(0,1,500)
y1 = np.sin(3*np.pi*x)*np.exp(-4*x)+np.cos(x)
y2 = y1 + np.sin(x)
y3 = 1.2
plt.plot(x,y1,'y')
plt.plot(x,y2,'g')
plt.fill_between(x,y1,y3,facecolor = 'blue', alpha = 0.5)
plt.show()
|