简体   繁体   English

matplotlib.pyplot.errorbar抛出错误它不应该?

[英]matplotlib.pyplot.errorbar is throwing an error it shouldn't?

I'm trying to make an errorbar plot with my data. 我正在尝试用我的数据制作一个错误栏图。 X is a 9 element ndarray. X是9元素的ndarray。 Y and Yerr are 9x5 ndarrays. Y和Yerr是9x5 ndarray。 When I call: 我打电话的时候:

matplotlib.pyplot.errorbar(X, Y, Yerr)

I get a ValueError: "yerr must be a scalar, the same dimensions as y, or 2xN." 我得到一个ValueError:“yerr必须是标量,与y或2xN的尺寸相同。”

But Y.shape == Yerr.shape is True. Y.shape == Yerr.shape是真的。

I'm running on 64 bit Windows 7 with Spyder 2.3.8 and Python 3.5.1. 我使用Spyder 2.3.8和Python 3.5.1在64位Windows 7上运行。 Matplotlib is up to date. Matplotlib是最新的。 I've installed Visual C++ Redistributable for Visual Studio 2015. 我已经为Visual Studio 2015安装了Visual C ++ Redistributable。

Any ideas? 有任何想法吗?

Edit: Some data. 编辑:一些数据。

X=numpy.array([1,2,3])
Y=numpy.array([[1,5,2],[3,6,4],[9,3,7]])
Yerr=numpy.ones_like(Y)

Hmmm.... 嗯....

By studying lines 2962-2965 of the module that raises the error we find 通过研究提出我们发现的错误的模块的第2962-2965行

if len(yerr) > 1 and not ((len(yerr) == len(y) and not (iterable(yerr[0]) and len(yerr[0]) > 1)))

From the data 从数据

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)

However, this will not be triggered if the following test is not passed: 但是,如果未通过以下测试,则不会触发此操作:

if (iterable(yerr) and len(yerr) == 2 and
                iterable(yerr[0]) and iterable(yerr[1])):
....

And it is not triggered, because len(yerr) = 3 而且它没有被触发,因为len(yerr)= 3

Everything seems to check out, except for the dimensionality. 除了维度之外,一切似乎都要检查出来。 This works: 这有效:

X = numpy.tile([1,2,3],3)
Y = numpy.array([1,5,2,3,6,4,9,3,7])
Yerr = numpy.ones_like(Y)

I am not sure what causes the error. 我不确定导致错误的原因。 The "l0, = " assignment also seems a little quirky. “l0,=”分配似乎有点古怪。

Maybe by "dimension of y" the docs actually meant 1xN... 也许通过“维度y”,文档实际上意味着1xN ......

Anyway, this could work: 无论如何,这可能有效:

for y, yerr in zip(Y, Yerr):
    matplotlib.pyplot.errorbar(X, y, yerr)

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

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