简体   繁体   English

python matplotlib之间的填充

[英]Python matplotlib fill between

Given the four curves in the image below, I am trying to fill everything above the top curve in red. 鉴于下图中的四个曲线,我试图用红色填充顶部曲线上方的所有内容。 My code below: 我的代码如下:

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

The fill_between call works well to color everything below expZeroFit in green, but seems to fail in coloring everything above expZeroFitC in red. fill_between调用可以很好地将expZeroFit之下的所有内容涂成绿色,但是似乎无法将expZeroFitC之上的所有内容涂成红色。

Any advice? 有什么建议吗?

在此处输入图片说明

Bit of a hard one when I'm just teaching myself matplotlib but it makes the learning it a bit more interesting. 当我只是自学matplotlib时,这有点困难,但这使学习变得更有趣。

But i think the problem answer is found in the definition of the how were functions in fill_between found here which says 但是我认为问题的答案是在如何找到在fill_between中的函数的定义中找到的它说

"where : array of bool (length N), optional, default: None “其中:布尔数组(长度N),可选,默认值:无

Define where to exclude some horizontal regions from being filled. 定义在哪里排除某些水平区域以使其不被填充。 The filled regions are defined by the coordinates x[where]. 填充的区域由坐标x [where]定义。 More precisely, fill between x[i] and x[i+1] if where[i] and where[i+1]. 更准确地说,如果where [i]和where [i + 1],则在x [i]和x [i + 1]之间填充。 Note that this definition implies that an isolated True value between two False values in where will not result in filling. 请注意,此定义意味着在其中的两个False值之间隔离的True值不会导致填充。 Both sides of the True position remain unfilled due to the adjacent False values." 由于相邻的False值,True位置的两侧均未填充。”

So a false value results in the not filling of the red. 因此,错误的值将导致红色无法填充。 So I would suggest looking at another way to fill in the space above expZeroFitC. 因此,我建议您寻找另一种方法来填充expZeroFitC上方的空间。

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

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