Python matplotlib填充
鉴于下图中的四条曲线,我试图用红色填充顶部曲线上方的所有内容。我的代码如下:Python matplotlib填充,python,Python,鉴于下图中的四条曲线,我试图用红色填充顶部曲线上方的所有内容。我的代码如下: # Fitting curve IV popt, _ = curve_fit(exponenial_func,xD, divider(yD), p0=(1,1,1), maxfev=10000) expZeroFitC = exponenial_func(x, *popt) plt.plot(x, expZeroFitC, label='Curve IV', color='#000000') alpha=1 plt.
# Fitting curve IV
popt, _ = curve_fit(exponenial_func,xD, divider(yD), p0=(1,1,1), maxfev=10000)
expZeroFitC = exponenial_func(x, *popt)
plt.plot(x, expZeroFitC, label='Curve IV', color='#000000')
alpha=1
plt.fill_between(x, expZeroFit, expZeroFitA, color='#4CFF33', alpha=alpha)
plt.fill_between(x, expZeroFitA, expZeroFitB, color='#F7E508', alpha=alpha)
plt.fill_between(x, expZeroFitB, expZeroFitC, color='#FFC300', alpha=alpha)
d = scipy.zeros(len(expZeroFit))
plt.fill_between(x, expZeroFit, where=expZeroFit>=d, interpolate=True, color='#3ECB1E')
d = scipy.zeros(len(expZeroFitC))
plt.fill_between(x, expZeroFitC, where=expZeroFitC<=d, interpolate=True, color='#DA3716')
#拟合曲线IV
popt,曲线拟合(指数函数,xD,除法器(yD),p0=(1,1,1),最大FEV=10000)
expZeroFitC=指数函数(x,*popt)
plt.plot(x,expZeroFitC,label='Curve IV',color='000000')
α=1
plt.fill_介于(x,expZeroFit,expZeroFit,color='#4CFF33',alpha=alpha)之间
plt.fill_介于(x,expZeroFitA,expZeroFitB,color='F7E508',alpha=alpha)之间
plt.fill_介于(x,expZeroFitB,expZeroFitC,color='FFC300',alpha=alpha)之间
d=scipy.zero(len(expZeroFit))
plt.fill_介于(x,expZeroFit,其中=expZeroFit>=d,interpolate=True,color='3ECB1E')
d=scipy.zero(len(expZeroFitC))
plt.fill_在(x,expZeroFitC,其中=expZeroFitC之间,这在我自学matplotlib时有点难
但这让学习它变得更有意思
但我认为问题的答案是在fill_中函数的定义中找到的,它说
其中:布尔数组(长度N),可选,默认值:无
定义从何处排除某些水平区域进行填充。填充区域由坐标x[where]定义。更准确地说,如果其中[i]和其中[i+1],则在x[i]和x[i+1]之间填充。请注意,此定义意味着,where中两个假值之间的独立真值不会导致填充。由于相邻假值,真位置的两侧保持未填充状态。”
所以一个错误的值会导致不填充红色。所以我建议用另一种方法来填充expZeroFitC上面的空间