【发布时间】:2015-02-04 15:29:38
【问题描述】:
我正在尝试从一些数据中绘制图表,但即使数据有 2 列,我也会遇到索引超出范围错误。代码如下:
import csv
from matplotlib import pyplot as plt
def getColumn(filename, column):
results = csv.reader(open(filename), delimiter='\t')
return [result[column] for result in results]
wavelength = getColumn('Bb69.dat.fix',0)
flux = getColumn('Bb69.dat.fix',1)
plt.figure('Bb69')
plt.xlabel('Wavelength (angstrom)')
plt.ylabel('flux (erg/cm^2/s/angstrom)')
plt.plot(wavelength,flux)
plt.show()
这是错误
Traceback (most recent call last):
File "SP12.py", line 14, in <module>
flux = getColumn('Bb69.dat.fix',1)
File "SP12.py", line 11, in getColumn
return [result[column] for result in results]
IndexError: list index out of range
【问题讨论】:
标签: python file csv indexing plot