绘制matplotlib中的错误栏

时间:2018-04-15 14:46:13

标签: python matplotlib matrix

我试图使用matplotlib制作比例图。当我尝试添加错误栏(错误为enew)时,它会给我一个ValueError[Scalar | N, N*1, N*2 array-like]

import matplotlib.pyplot as plt
import numpy as np

pcd = np.array([0.25,0.56,0.66,0.75,0.88])
wpcd = np.array([0.40,0.53,0.80])
wf = np.array([0.33,0.50,0.60,0.80,0.88])
wf1 = np.array([0.50,0.60,0.80])
en = np.array([0.108,0.124,0.122,0.108,0.08])
ew = np.array([0.126,0.128,0.103])

plt.plot(wf,pcd,'o')
plt.errorbar(wf,pcd,yerr = en, fmt = 'o')
plt.plot(wf1,wpcd,'*')
plt.errorbar(wf1,wpcd,yerr = ew, fmt = 'o')
plt.show()

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容:

plt.errorbar(wf, pcd, yerr=en, xerr=en, fmt='o')
plt.show()