尝试绘制范围从负值到正值的不对称误差条时遇到错误。我修改了文档中的示例:
import numpy as np
import matplotlib.pyplot as plt
# example data
x = np.arange(0, 4, 1)
y = -0.2* x
# example error bar values that vary with x-position
error = 0.1 + 0.2 * x
# error bar values w/ different -/+ errors that
# also vary with the x-position
lower_error = -1 * error
upper_error = 4* error
asymmetric_error = [lower_error, upper_error]
plt.errorbar(x, y, yerr=asymmetric_error, fmt='.', ecolor = 'red')
plt.show()
给出了以下情节:
但对于不对称误差具有以下值:
array([-0.1, -0.3, -0.5, -0.7]), array([0.4, 1.2, 2. , 2.8])]
这似乎遵循文档,所以我不确定是什么原因造成的。
较低误差前面不需要负数。
import numpy as np
import matplotlib.pyplot as plt
# example data
x = np.arange(0, 4, 1)
y = -0.2* x
# example error bar values that vary with x-position
error = 0.1 + 0.2 * x
# error bar values w/ different -/+ errors that
# also vary with the x-position
lower_error = error
upper_error = 4*error
asymmetric_error = np.array(list(zip(lower_error, upper_error))).T
plt.errorbar(x, y, yerr=asymmetric_error, fmt='.', ecolor = 'red')
plt.show()
Output:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)