ax1.fill_betweenx(y,0, x1, facecolor ='green') ax1.set_title('Fill_Betweenx x1 and 0') ax2.fill_betweenx(y, x1,1, facecolor ='green') ax2.set_title('Fill_Betweenx x1 and 1') ax3.fill_betweenx(y, x1, x2, facecolor ='green') ax3.set_title('Fill_Betweenx x1 and y2'...
ax.fill_betweenx(y, x1, x2, where = x2 <= x1, facecolor ='black', alpha = 0.8) ax.set_title('matplotlib.axes.Axes.fill_betweenx Example1') plt.show()
importnumpyasnpimportmatplotlib.pyplotaspltfromscipy.integrateimportquaddefintegrand(x):returnx **2result, error = quad(integrand,0,1) x = np.linspace(0,1,100) y = x **2fig, ax = plt.subplots() ax.plot(x, y,'r', linewidth=2) ax.fill_between(x, y, where=(y>0), color='blue...
ax.fill_between(X, Y2, Y8, facecolor='#9ad3bc',alpha=0.6)#填充颜色在Y2和Y8(基线)之间,下同。alpha为透明度,1为不透明,可根据需要调整 ax.fill_between(X, Y3, Y8, facecolor='red') ax.fill_between(X, Y4, Y8, facecolor='lightcoral',alpha=0.6) ...
为了在两条线之间添加阴影,我们可以使用fill_between函数。代码如下: ax.fill_between(x,y1,y2,alpha=0.2) 1. fill_between函数的三个参数分别表示x轴数据、y1轴数据和y2轴数据。通过设置alpha参数,我们可以调整阴影的透明度。 3.6 显示图形 最后,我们使用show函数将图形显示出来。代码如下: ...
情形一:axf=ax.fill_between(x,np.sin(x),amod_sin(x),facecolor='gray') 情形二:填充指定区域: #在fill_between中使用where语句进行填充,where是一个非常便捷的参数,需要一个布尔数组来指定额外的填充条件,用来选择要填充的区域的布尔数组是amod_sin(x)-np.sin(x)>0 ...
fig, [ax, ax1] = plt.subplots(2,1, sharex =True) ax.plot(x, y1, x, y2, color ='black') ax.fill_between(x, y1, y2, where = y2 >y1, facecolor ='green', alpha =0.8) ax.fill_between(x, y1, y2, where = y2 <= y1, ...
x = np.linspace(0, np.pi) y_sin = np.sin(x) y_cos = np.cos(x) ax1.plot(x, y_sin) ax2.plot(x, y_sin, 'go--', linewidth=2, markersize=12) ax3.plot(x, y_cos, color='red', marker='+', linestyle='dashed')
ma.masked_greater(x2, 1.0) # 绘制两条正弦波曲线,可以看到曲线(X2,y)中,X2中数值大于1的部分没有绘制 ax1.plot(x1, y, x2, y, color='red') # 填充两条曲线之间满足where条件的区域,可以看到曲线(X2,y)中,X2中数值大于1的区域没有被填充 ax1.fill_betweenx(y, x1, x2, where=x2 >= ...
x = np.linspace(0, 2*np.pi, 400) y = np.sin(x**2) f, [[ax1,ax2],[ax3,ax4]] = plt.subplots(2, 2) plt.subplots_adjust(wspace=0.5,hspace=0.5) ax1.plot(x, y) ax1.set_title('Sharing Y axis') ax2.scatter(x, y) ...