0

我有一个包含 6 列的数据文件(data.txt):第 1 列和第 4 列是 x 和 y 数据,第 2 列和第 3 列是第 1 列的(不对称)误差线,第 4 列和第 5 列是(第 6 列的不对称)误差线:

100 0.77 1.22 3   0.11 0.55
125 0.28 1.29 8   0.15 0.53
150 0.43 1.11 14  0.10 0.44
175 0.33 1.01 22  0.18 0.49
200 0.84 1.33 34  0.11 0.48

我想绘制这个。我知道我需要使用

import numpy as np
import matplotlib.pyplot as plt

plt.plotfile(......)

plt.show()

plotfile 中括号之间的位是我不确定如何将这些错误栏与列相关联的地方(以及我错过的任何其他内容)。

4

1 回答 1

1

使用numpy.loadtxt完美:

import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt("data.txt")
x = data[:, 0]
y = data[:, 3]
# errorbar expects array of shape 2xN and not Nx2 (N = len(x)) for xerr and yerr
xe = data[:, 1:3].T
ye= data[:, 4:].T

plt.errorbar(x, y, xerr=xe, yerr=ye, fmt=".-")

# if you want a log plot:
plt.xscale("log")
plt.yscale("log")

plt.show()
于 2016-07-14T13:46:05.427 回答