Python绘画3D图
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()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· Ollama——大语言模型本地部署的极速利器
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· Windows编程----内核对象竟然如此简单?
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用