-
Notifications
You must be signed in to change notification settings - Fork 0
/
chart.py
executable file
·85 lines (62 loc) · 1.86 KB
/
chart.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author caoxm-me <[email protected]>
# Email
# Date
# Contributor YongXin SHI <[email protected]>
# Last_update_time_at 2017/4/29
# pylab 在 python-matplotlib 模块中
import pylab as pl
import xlrd as xl
#import sourcedata
#da = sourcedata.Data()
def open_excel(file= 'file.xls'):
try:
data = xl.open_workbook(file)
return data
except Exception.e:
print(str(e))
def data_pre(data):
index = [] #存放索引
for i in (range(len(data)-2)):
if not (data[i+1]>data[i] and data[i+1]>data[i+2]):
index.append(i+1)
return index
def filter_times(x, y, times):
i = 0
while i<times:
i=i+1
intensity_index = data_pre(y)
intensity = data_filter(y, intensity_index)
# print(type(intensity))
print("filter y:", intensity)
wave = data_filter(x, intensity_index)
print("filter x:", wave)
return(wave, intensity)
def data_filter(data,index):
# 过滤无效数据
for i in index:
data[i]=0
def is_zero(x):
return(x!=0)
data=(list(filter(is_zero,data)))
return data
def draw_chart(num):
# 打开表格,file为excel文件对象
file = open_excel('c4h10.xlsx')
# 按序号获取excel工作表,sheets()返回一个列表,由下表指定工作表
table = file.sheets()[0]
# 按列获取工作表数据,第一列是波长
r_wave = table.col_values(0)
# 按列获取工作表数据,第二列是强度,以后同理,每两列为一组(波长,强度)
r_intensity = table.col_values(num)
wave, intensity=filter_times(r_wave, r_intensity, 100)
#print(intensity)
# 绘图
pl.plot(wave, intensity)
for num_n in [1, 3, 5, 7, 9]:
#print(num_n)
draw_chart(num_n)
# 显示图像
pl.show()
pl.close()