Я делаю приложение для полуавтоматической отчетности по некоторым научным инструментам. Мне нужно иметь возможность выбрать файл Excel с помощью диалогового окна файла и отобразить эти выбранные данные на графике на моей странице графиков. Я могу выбрать файлы Excel отлично, но у меня возникают проблемы с чтением и построением данных. Вот что у меня так далеко.
class PageThree(tk.Frame):
#figures page
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent, bg='white', bd=3, relief='sunken')
topbar = tk.Frame(self, bg='white', height=50)
topbar.pack(side='top', fill='x', pady=20)
topbar3 = tk.Frame(self, bg='white', height=50)
topbar3.pack(side='top', fill='x', pady=0, padx=160)
button1 = ttk.Button(topbar3, text="Select Instrument 1",
command=plotdata1)
button1.pack(side='left', anchor='center', padx=91)
button2 = ttk.Button(topbar3, text="Select Instrument 2",
command=lambda: controller.show_frame(StartPage))
button2.pack(side='left', anchor='center', padx=91)
button3 = ttk.Button(topbar3, text="Select Instrument 3",
command=lambda: controller.show_frame(StartPage))
button3.pack(side='left', anchor='center', padx=91)
button4 = ttk.Button(topbar3, text="Select Instrument 4",
command=lambda: controller.show_frame(StartPage))
button4.pack(side='left', anchor='center', padx=91)
topbar2 = tk.Frame(self, bg='white', height=50)
topbar2.pack(side='top', fill='x', pady=0, padx=160)
button1 = ttk.Button(topbar2, text="Select Data1",
command=selectdata1)
button1.pack(side='left', anchor='center', padx=110)
button2 = ttk.Button(topbar2, text="Select Data2",
command=selectdata1)
button2.pack(side='left', anchor='center', padx=110)
button3 = ttk.Button(topbar2, text="Select Data3",
command=selectdata1)
button3.pack(side='left', anchor='center', padx=110)
button4 = ttk.Button(topbar2, text="Select Data4",
command=selectdata1)
button4.pack(side='left', anchor='center', padx=110)
button5 = ttk.Button(topbar, text="Select Interval",
command=lambda: controller.show_frame(StartPage))
button5.pack(side='top', anchor='n')
f = Figure(figsize=(5,5), dpi= 80)
f.suptitle('Project Data Display', fontsize=20)
a = f.add_subplot(2,2,1)
b = f.add_subplot(2,2,2)
c = f.add_subplot(2,2,3)
d = f.add_subplot(2,2,4)
a.title.set_text('Instrument1')
b.title.set_text('Instrument2')
c.title.set_text('Instrument3')
d.title.set_text('Instrument4')
#a.plot([1,2,3,4,5,6,7,8],[1,5,7,3,5,8,6,7])
aData = pd.read_excel('Slope_Movement_SSR.xlsx', sheet_name='Sheet1')
vDeformation = aData['Deformation']
vDates = aData['Time']
#a.plot(vDates,vDeformation)
b.plot(vDates,vDeformation)
c.plot(vDates,vDeformation)
d.plot(vDates,vDeformation)
canvas = FigureCanvasTkAgg(f, self)
canvas.draw()
canvas.get_tk_widget().pack(side='bottom', pady=20, expand=True, fill='both', anchor='s')
def selectdata1():
C = filedialog.askopenfilename(initialdir = "/",title = "Select Data",filetypes = (("Excel files","*.xlsx"),("all files","*.*")))
df = pd.read_excel(C, sheet_name='Sheet1')
def plotdata1():
vDates = df['Time']
vPPVX = df['PPVX']
a.plot(vDates,vDeformation)