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

喜夏-厌秋 提交于 2019-12-06 16:01:01

Maybe by "dimension of y" the docs actually meant 1xN...

Anyway, this could work:

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

Hmmm....

By studying lines 2962-2965 of the module that raises the error we find

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!