簡體   English   中英

matplotlib.pyplot.errorbar拋出錯誤它不應該?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM