简体   繁体   English

功能之间的 Matplotlib 填充

[英]Matplotlib fill between functionality

I saw the use of fill_between in in one the sentdex tutorial on matplotlib.我在 matplotlib 的 senddex 教程中看到了 fill_between 的使用。 The code was like代码就像

import matplotlib.pyplot as plt

axis=plt.subplot2grid((1,1),(0,0)) #a and b are lists of equal sizes
axis.plot(a,b)
axis.fill_between(a,b,34,where=(b>34),facecolor='r',alpha=.5)

Now his code ran fine and what he got in output was colored face on the portion where values in b were larger than 34. But the same gives error for me :现在他的代码运行良好,他在输出中得到的东西在 b 中的值大于 34 的部分是彩色的。但同样给我带来了错误:

TypeError: '>' not supported between instances of 'list' and 'int'类型错误:“list”和“int”的实例之间不支持“>”

I cant find how to use the where functionality我找不到如何使用 where 功能

So, I'm following same tutorial and I had same problem.所以,我正在学习相同的教程,但遇到了同样的问题。 You need to import numpy library and then convert your list to numpy array and then everything will work perfectly.您需要导入 numpy 库,然后将您的列表转换为 numpy 数组,然后一切都会完美运行。

import matplotlib.pyplot as plt
import numpy

b = numpy.array(b)

axis=plt.subplot2grid((1,1),(0,0)) #a and b are lists of equal sizes
axis.plot(a,b)
axis.fill_between(a,b,34,where=(b>34),facecolor='r',alpha=.5)

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

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