Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的Matplotlib非对称错误栏打印_Python_Matplotlib_Plot_Errorbar - Fatal编程技术网

python中的Matplotlib非对称错误栏打印

python中的Matplotlib非对称错误栏打印,python,matplotlib,plot,errorbar,Python,Matplotlib,Plot,Errorbar,尝试绘制从负值到正值的非对称条时出错。我修改了文档中的示例: 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 -/+ err

尝试绘制从负值到正值的非对称条时出错。我修改了文档中的示例:

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()
它给出了以下曲线图:

但不对称误差的值如下:

数组([-0.1,-0.3,-0.5,-0.7]),数组([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()
输出: