【发布时间】:2018-11-03 08:41:06
【问题描述】:
我在 matplotlib 上的 sentdex 教程中看到了 fill_between 的使用。 代码就像
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)
现在他的代码运行良好,他在输出中得到的是 b 中值大于 34 的部分的彩色面部。 但同样给我带来了错误:
TypeError: '>' 在 'list' 和 'int' 的实例之间不支持
我找不到如何使用 where 功能
【问题讨论】:
-
But the same gives error for me : TypeError: '>' not supported between instances of 'list' and 'int'当你写什么不同的代码时,会抛出这个错误呢? -
请创建一个minimal reproducible example。在任何情况下,本教程可能一直在使用
numpy数组,不会出现此错误 -
DavidG 似乎打对了。 OP 的代码有一个注释(#a 和 b 是列表...)如果 b 真的是一个列表而不是一个 numpy 数组,则错误告诉您确切的问题:在“列表”和'int'。
-
对不起我的错误。这是一个 numpy 数组,现在工作正常。
标签: python matplotlib