[英]Different length of error bars in Matplotlib
我想繪制一個圖形,每個點都有不同的誤差,與值無關。
我的代碼在這里:
import matplotlib.pyplot as plt
x=[1,2,3,4,5,6]
y=[10,20,30,40,50,60]
errorx=[0.1,0.3,0.7,0.6,1,1.5,0.2]
errory=[0.1,0.8,0.4,2.3,0.1,1.2,0.6]
plt.errorbar(x,y,yerr=None,xerr=None)
plt.plot(x,y)
我沒有得到我想要的; 我想要沒有連接點和 x 和 y 誤差條的線
首先,您在示例中將yerr
和xerr
設置為None
(如您的評論中所示),因此不會顯示錯誤欄。 其次,您的 x 和 y 錯誤列表的長度與 x 和 y 坐標的長度不同。 因此,如果你試圖繪制它,你會得到一個ValueError: xerr must be a scalar, the same dimensions as x, or 2xN.
同樣的事情也會發生在你的 y 錯誤上。 可以在此處找到錯誤欄文檔。
使用您的數據的工作示例如下所示:
import matplotlib.pyplot as plt
x = [1,2,3,4,5,6]
y = [10,20,30,40,50,60]
errorx = [0.1,0.3,0.7,0.6,1,1.5] #now the same length as x and y
errory = [0.1,0.8,0.4,2.3,0.1,1.2]
plt.errorbar(x, y, yerr=errory, xerr=errorx, linestyle='')
#change linestyle to not connect the points
plt.show()
這會產生以下圖表:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.