import mpl_toolkits.axisartist as axisartist from scipy.optimize import curve_fit from pandas import DataFrame import matplotlib.pyplot as plt import numpy as np import pylab as mpl from tkinter import * import data as gl_data import pandas as pd import tkinter import sys import tkinter as tk from tkinter import filedialog mpl.rcParams['font.sans-serif'] = ['SimHei'] # 解决matplotlib中文不显示问题 plt.rcParams['axes.unicode_minus'] = False # 解决matplotlib负数坐标显示问题 # 创建一个二维数组sampleData,用于存储样本数据 sampleData = [] def askfile():# 从本地选择一个文件,并返回文件的路径 global sampleData # 弹出文件选择对话框,选择要打开的文本文件 file_path = filedialog.askopenfilename(filetypes=[('Text Files', '*.txt')]) # 如果没有选择文件,直接返回 if not file_path: return # 步骤1:打开样本数据集文件并读取每行数据 with open(file_path, 'r') as file: lines = file.readlines() # 步骤2:遍历所有行,将每行数据解析为sx和sy值,转换为浮点数并存储到sampleData中 for line in lines: sx, sy = line.strip().split(' ') sx = float(sx) sy = float(sy) sampleData.append([sx, sy]) # # 步骤3:使用循环遍历样本数据并打印出来 # for data in sampleData: # print(data) if __name__ == '__main__': askfile()