import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
import xlrd
import xlwt
import tkinter as tk
from tkinter import filedialog
def read_excel():
# 打开文件
tk.Tk().withdraw();
file_path = filedialog.askopenfilename(title='Select the diagnostic instrument .xls file', filetypes=[('Excel','*.xls'),('Excel','*.xlsx'), ('All Files', '*')])
workBook = xlrd.open_workbook(file_path);
# 1.获取sheet的名字
# 1.1 获取所有sheet的名字(list类型)
allSheetNames = workBook.sheet_names();
print(allSheetNames);
# 1.2 按索引号获取sheet的名字(string类型)
sheet1Name = workBook.sheet_names()[0];
print(sheet1Name);
# 2. 获取sheet内容
## 2.1 法1:按索引号获取sheet内容
sheet1_content1 = workBook.sheet_by_index(0); # sheet索引从0开始
## 2.2 法2:按sheet名字获取sheet内容
sheet1_content2 = workBook.sheet_by_name('Sheet1');
# 3. sheet的名称,行数,列数
print(sheet1_content1.name,sheet1_content1.nrows,sheet1_content1.ncols);
# 4. 获取整行和整列的值(数组)
rows = sheet1_content1.row_values(1); # 获取第2行内容
cols = sheet1_content1.col_values(0); # 获取第1列内容
print(cols);
# 5. 获取单元格内容(三种方式)
# print(sheet1_content1.cell(1, 0).value);
# print(sheet1_content1.cell_value(2, 2));
# print(sheet1_content1.row(2)[2].value);
# 6. 获取单元格内容的数据类型
# Tips: python读取excel中单元格的内容返回的有5种类型 [0 empty,1 string, 2 number, 3 date, 4 boolean, 5 error]
# print(sheet1_content1.cell(1, 0).ctype);
return cols
if __name__ == '__main__':
x=read_excel();
# mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
# theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
# z = np.linspace(-2, 2, 100)
# r = z**2 + 1
# x = r * np.sin(theta)
# y = r * np.cos(theta)
ax.plot(x, x, x, label='parametric curve')
ax.legend()
plt.show()