我想从文本文件(或.tbl文件)中获取数据并绘制文件中两列的数据。我在扫描字符串文字时得到错误 - " EOL"我尝试过这样的事情:
import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('uid.txt',
dtype = {
'names':
('HJD', 'RELATIVE_DATE', 'PHASE',
'RELATIVE_FLUX', 'RELATIVE_FLUX_UNCERTAINTY', 'RELATIVE_FLUX_WITHOUT_SYSTEMATICS',
'DIFFERENCE_DATA_VS_MODEL', 'MODEL_FIT', 'MODEL_FIT_WITHOUT_SYSTEMATICS', 'AIRMASS'),
'formats': ('f64', 'f64', 'f64', 'f64', 'f64', 'f64', 'f64', 'f64', 'f64', 'f64')
})
x = data['PHASE']
y = data['RELATIVE_FLUX_WITHOUT_SYSTEMATICS']
xlabel('orbital phase')
ylabel('flux')
plot(x, y, 'go')
plt.show()
答案 0 :(得分:0)
我建议改为使用pandas.read_csv()
或numpys np.genfromtxt()
方法,因此pandas
方法对于大量数据来说要快得多。有关文档,请查看此处:https://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html和此处:https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html。此外,很难确定您的错误来自哪里,而不了解您的数据。