[英]matplotlib.pyplot.errorbar is throwing an error it shouldn't?
我正在尝试用我的数据制作一个错误栏图。 X是9元素的ndarray。 Y和Yerr是9x5 ndarray。 我打电话的时候:
matplotlib.pyplot.errorbar(X, Y, Yerr)
我得到一个ValueError:“yerr必须是标量,与y或2xN的尺寸相同。”
但Y.shape == Yerr.shape
是真的。
我使用Spyder 2.3.8和Python 3.5.1在64位Windows 7上运行。 Matplotlib是最新的。 我已经为Visual Studio 2015安装了Visual C ++ Redistributable。
有任何想法吗?
编辑:一些数据。
X=numpy.array([1,2,3])
Y=numpy.array([[1,5,2],[3,6,4],[9,3,7]])
Yerr=numpy.ones_like(Y)
嗯....
通过研究提出我们发现的错误的模块的第2962-2965行
if len(yerr) > 1 and not ((len(yerr) == len(y) and not (iterable(yerr[0]) and len(yerr[0]) > 1)))
从数据
1 T len(yerr) > 1
2 T len(yerr) == len(y)
3 T iterable(yerr[0])
4 T len(yerr[0]) > 1
5 T 1 and not (2 and not (3 and 4)
但是,如果未通过以下测试,则不会触发此操作:
if (iterable(yerr) and len(yerr) == 2 and
iterable(yerr[0]) and iterable(yerr[1])):
....
而且它没有被触发,因为len(yerr)= 3
除了维度之外,一切似乎都要检查出来。 这有效:
X = numpy.tile([1,2,3],3)
Y = numpy.array([1,5,2,3,6,4,9,3,7])
Yerr = numpy.ones_like(Y)
我不确定导致错误的原因。 “l0,=”分配似乎有点古怪。
也许通过“维度y”,文档实际上意味着1xN ......
无论如何,这可能有效:
for y, yerr in zip(Y, Yerr):
matplotlib.pyplot.errorbar(X, y, yerr)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.