import xlrd
import openpyxl
from tkinter import filedialog
from tkinter import *
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import numpy as np
root = Tk()
root.title("练习窗口")
root.geometry('320x240+10+10')
label1=Label(root,text='测试窗口')
label1.place(x=0,y=0)
Text = Text(root,width = 50,height=10)
Text.place(x=0,y=30)
fig = plt.figure(figsize=(10,4),dpi=100)
f_plot =fig.add_subplot(111)
canvas_spice = FigureCanvasTkAgg(fig,root)
canvas_spice.get_tk_widget().place(x=0,y=200)
def get_xl():
file = filedialog.askopenfilename()
read = xlrd.open_workbook(file)
sheet1 = read.sheet_by_index(0)
nrows = sheet1.nrows
ncols = sheet1.ncols
a=2
b=0
x1 =[]
y1 =[]
for i in range(nrows):
for j in range(ncols):
ctype = sheet1.cell(i,j).ctype
if ctype ==1:
value = sheet1.cell_value(i,j)
a+=1
b+=1
if a>5 and a%3==0:
value2 = sheet1.cell_value(i,j)
y=(value2.strip('Ang= °'))
y1.append(float(y))
if b%3==0:
value3 = sheet1.cell_value(i,j)
x1.append(value3[10:])
if ctype ==0:
break
plt.rcParams['font.sans-serif']='SimHei'
f_plot.clear()
plt.xlabel('日期',size = 20)
plt.ylabel('天顶角(单位°)',size =20)
plt.title('N20 卫星 5—6月,天顶角情况',size = 20)
plt.axis([0,30,0,90])
plt.plot(x1,y1)
plt.grid(True)
canvas_spice.draw()
button = Button(root,text='选择文件',bg='lightblue',width=10,command=get_xl)
button.place(x=400,y=1)
root.mainloop()