我正在尝试(在同一个图中)从 Excel 工作表中绘制一些数据,并且我想要一个可变长度的字符串列表作为输入,对应于不同的材料。我收到以下错误: TypeError: 'NoneType' object is not iterable 我真的不明白为什么。这是代码:
import xlrd
import matplotlib.pyplot as plt
from numpy import *
def transmittance(*glass):
wb=xlrd.open_workbook('schott_optical_glass_catalogue_excel_december_2012.xls')
sheet1=wb.sheet_by_index(0)
transm_index=[] #lista vuota
plt.figure(1)
plt.xlabel('wavelength $\lambda$[nm]')
plt.ylabel('transmittance')
for item in glass:
for i in range(sheet1.nrows):
if sheet1.cell_value(i,0)==glass:
reversed_transmission=sheet1.row_values(i,37,67)
transm_index=reversed_transmission[::-1]
new_transm_index=[float(ni) for ni in transm_index ]
wavel_range=sheet1.row_values(3,37,67)
temp_wavel= [k.split('/')[1] for k in wavel_range]
wRange=map(int,temp_wavel[::-1])
plt.plot(wRange,new_transm_index, 'r-')
plt.grid(True, which="both")
plt.show()
return new_transm_index, wRange
if __name__=='__main__':
new_transm_index=transmittance('N-BASF64','N-BK7')
print 'get tuple length and glass name: ' ,new_transm_index