-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy7.py
211 lines (183 loc) · 6.52 KB
/
py7.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#---------------------------------------------------------------
# Plot the excel data by tkinter & matplotlib & pandas
#
# Created: 2017/10/19
#---------------------------------------------------------------
# import module
from tkinter import *
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import pandas as pd
# tkinter create
root = Tk()
# tkinter frame size
root.geometry("%dx%d+%d+%d" % (500, 50, 0, 0))
# tkinter frame title
root.title("Device-Patient-Variable-Result Line")
# device, patient, varaibal, result index for select
deviceNum = 0
patientNum = 0
variableNum = 0
resultNum = 0
# menu iterms
choices_Device = ['Device 1', 'Device 2', 'Device 3']
choices_Patient = ['Patient 1', 'Patient 2']
choices_Variable = ['Variable 1', 'Variable 2']
choices_Result = ['Result 1', 'Result 2', 'Result 3', 'Result 4' ]
# initial value for select
varDevice = StringVar(root)
varPatient = StringVar(root)
varVariable = StringVar(root)
varResult = StringVar(root)
varDevice.set( choices_Device[ deviceNum ] )
varPatient.set( choices_Patient[ patientNum ] )
varVariable.set( choices_Variable[ variableNum ] )
varResult.set( choices_Result[ resultNum ] )
# real x,y number data in execel
allXList = []
allYList = []
excelFileName = "D://Sampledata.xlsx"
#-----------------------------------------
# excel data parsing class
# out : allXList - real x number list
# allYList - real y number list
#-----------------------------------------
class ExecelClass:
# get the device data
def getData(self):
# load the execel file
execelData = pd.ExcelFile( excelFileName )
# get the sheet data
sheetIdx = 0
columCnt = 0
while sheetIdx < 3:
# get the data for one sheet
data = execelData.parse(execelData.sheet_names[sheetIdx])
# the number of rows
rowCnt = len(data)
# The column headings
columCnt = len(data.columns)
# get the real data
idx = 0
while idx < columCnt:
realPlotData = data[data.columns[idx]]
# get the real ploat number data only
rIdx = 0
# 4 - real data start index
while rIdx < 4:
del realPlotData[ rIdx ]
rIdx += 1
if idx % 2 == 0:
allXList.append( realPlotData )
else:
allYList.append( realPlotData )
idx = idx + 1
sheetIdx += 1
# ---------------------------------------------------
# Get the x, y data
# inp:
# deviceNum: 0 ~ 2
# patientNum: 0 -1
# variableNum: 0 - 1
# resultNum: 0 - 3
# out:
# tuple index of x,y data
# ---------------------------------------------------
def GetXYData():
global deviceNum, patientNum, variableNum, resultNum
# get the index in data
idexInData = deviceNum * 16 + patientNum * 8 + variableNum * 4 + resultNum
return allXList[ idexInData ], allYList[ idexInData ]
# ---------------------------------------------------
# Plot the x, y data
#----------------------------------------------------
def plotXY ():
# load the x,y for plot
xx, yy = GetXYData()
# pre plot cls
plt.clf()
# sub window title
subTitle = "Device " + str( deviceNum + 1 ) + "- Patient " + str( patientNum + 1 ) + "- Variable " \
+ str( variableNum + 1 ) + "- Result " + str( resultNum + 1 )
plt.suptitle (subTitle, fontsize=16)
# plot x, y
plt.plot( xx, yy, color='blue' )
plt.ylabel("Y", fontsize=14)
plt.xlabel("X", fontsize=14)
plt.show()
# ---------------------------------------------------
# Device menu event handler
#----------------------------------------------------
def OptionMenu_SelectionEvent_Device(event):
global deviceNum
if choices_Device[ deviceNum ] != event:
deviceNum = 0
while( deviceNum < 3 ):
if choices_Device[ deviceNum ] == event:
break
else:
deviceNum += 1
plotXY()
pass
# ---------------------------------------------------
# Patient menu event handler
#----------------------------------------------------
def OptionMenu_SelectionEvent_Patient(event):
global patientNum
if choices_Patient[ patientNum ] != event:
patientNum = 0
while( patientNum < 2 ):
if choices_Patient[ patientNum ] == event:
break
else:
patientNum += 1
plotXY()
pass
# ---------------------------------------------------
# Variable menu event handler
#----------------------------------------------------
def OptionMenu_SelectionEvent_Variable(event):
global variableNum
if choices_Variable[ variableNum ] != event:
variableNum = 0
while( variableNum < 2 ):
if choices_Variable[ variableNum ] == event:
break
else:
variableNum += 1
plotXY()
pass
# ---------------------------------------------------
# Result menu event handler
#----------------------------------------------------
def OptionMenu_SelectionEvent_Result(event):
global resultNum
if choices_Result[resultNum] != event:
resultNum = 0
while (variableNum < 4):
if choices_Result[resultNum] == event:
break
else:
resultNum += 1
plotXY()
pass
# Device menu make
optionDevice = OptionMenu(root, varDevice, *choices_Device, command = OptionMenu_SelectionEvent_Device )
optionDevice.pack(side='left', padx = 10, pady = 10)
# Patient menu make
optionPatient = OptionMenu(root, varPatient, *choices_Patient, command = OptionMenu_SelectionEvent_Patient )
optionPatient.pack(side='left', padx = 10, pady = 10)
# Variable menu make
optionVariable = OptionMenu(root, varVariable, *choices_Variable, command = OptionMenu_SelectionEvent_Variable )
optionVariable.pack(side='left', padx = 10, pady = 10)
# Result menu make
optionResult = OptionMenu(root, varResult, *choices_Result, command = OptionMenu_SelectionEvent_Result )
optionResult.pack(side='left', padx = 10, pady = 10)
# load the excel data
excelData = ExecelClass()
excelData.getData()
# plot
plotXY()
# event waiting
root.mainloop()