Matplotlib errorbar 按图中的一个因子缩放

Matplotlib errorbar scaled by a factor in plot

我正在从名为 test.csv 的 CSV 文件中绘制数据,该文件的值如下:

X                      Y            Yerrmin              Yerrmax
13.629119553139 0.13237415706937    0.115879894547257   0.14748971609137
55.3872849395824    0.14385506424916    0.13237415706937    0.153752686711682
208.442201941724    0.144454558978827   0.129650059586552   0.158954011478447
544.589674426085    0.151216201294351   0.13515549098632    0.168483298334671
968.990798410664    0.149341335862913   0.135718731529535   0.164331292710806
1305.01533678836    0.146268074690858   0.13073290613871    0.162970154348788
1596.62602210143    0.14748971609137    0.13292580681435    0.165016119097793

在我的代码中,我有:

testK = np.genfromtxt("test.csv", delimiter=",", names=["X", "Y", "Yerrmin", "Yerrmax"])
testK_yerr=[testK['Yerrmin'], testK['Yerrmax']]
plt.errorbar(testK['X'], testK['Y'], yerr=testK_yerr, fmt='sk')
plt.savefig("test_plot.pdf")

这给出了情节:

我找不到错误栏按乘法因子缩放的问题

您的 Yerrmin 值应该小于您希望误差线向下延伸到的数据点。因此,当您的第一个 Y 点是 0.13 时,Y 误差将向下扩展到 0.13-0.12 = 0.01,这就是它所在的位置。如果 Yerrmin 实际上是最小 Y 值,即您希望误差带从 0.115 扩展到 0.147,那么您需要制作新值以传递给函数,如

testK_yerr=[testk['Y']-testK['Yerrmin'], testK['Yerrmax']-testK['Y']]

并通过那些代替