繁体   English   中英

python matplotlib之间的填充

[英]Python matplotlib fill between

鉴于下图中的四个曲线,我试图用红色填充顶部曲线上方的所有内容。 我的代码如下:

# 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')

fill_between调用可以很好地将expZeroFit之下的所有内容涂成绿色,但是似乎无法将expZeroFitC之上的所有内容涂成红色。

有什么建议吗?

在此处输入图片说明

当我只是自学matplotlib时,这有点困难,但这使学习变得更有趣。

但是我认为问题的答案是在如何找到在fill_between中的函数的定义中找到的它说

“其中:布尔数组(长度N),可选,默认值:无

定义在哪里排除某些水平区域以使其不被填充。 填充的区域由坐标x [where]定义。 更准确地说,如果where [i]和where [i + 1],则在x [i]和x [i + 1]之间填充。 请注意,此定义意味着在其中的两个False值之间隔离的True值不会导致填充。 由于相邻的False值,True位置的两侧均未填充。”

因此,错误的值将导致红色无法填充。 因此,我建议您寻找另一种方法来填充expZeroFitC上方的空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM