You are currently opening a dialog using tkinter.
I got the file path, but I would like to replace it with f1, f2.
What should I do?
import matplotlib.pyplot as plt
import numpy as np
importos
import tkinter
from tkinter import messagebox
from tkinter import filedialog
root=tkinter.Tk()
root.title('Smile Mountain') #Title
root.geometry('400x200') # Size Horizontal x Vertical
# What to do when you press the selct button?
def select_click():
messagebox.showinfo('select','true data')
messagebox.showinfo('select', 'measured data')
fileType=[('Excel file', '*.txt')]# Specify file type to Excel file
fileType=[('Excel file', '*.txt')]# Specify file type to Excel file
iniDir1 = os.path.abspath(os.path.dirname(__file__))# Initial View Folder
iniDir2=os.path.abspath(os.path.dirname(__file__))#Initial View Folder
filepath1=filedialog.askopenfilename (filetypes=fileType, initialdir=iniDir1)
filepath2=filedialog.askopenfilename (filetypes=fileType, initialdir=iniDir2)
messagebox.showinfo ('Selected File', filepath1)
messagebox.showinfo ('Selected File', filepath2)
# Create Buttons
selectButton=tkinter.Button(root, text='fast Select', command=select_click)
selectButton.pack()
root.mainloop()
x1_list = [ ] # Define x_list for data1 storage
z1_list=[]#Define z_list for data1 storage
x2_list = [ ] # Define x_list for data2 storage
z2_list=[]#Define z_list for data2 storage
f1 = open ('root')
f2 = open('filepath2')# Read the file containing the data you want to plot in r(read)t(text) mode
# data1 loading
for line inf1:
data1 = line [:-1].split('')
x1_list.append (float(data1[0]))
z1_list.append(float(data1[1]))
# data2 loading
for line inf2:
data2=line[:-1].split('')
x2_list.append (float(data2[0]))
z2_list.append(float(data2[1]))
##
plt.xlabel('X')# x-axis label
plt.ylabel('Z')#y-axis label
plt.plot(x1_list, z1_list, color="White", alpha=0.8, linewidth=4.0, label="data1")
plt.plot(x2_list, z2_list, color="White", alpha=0.8, linewidth=4.0, label="data2")
plt.legend()
plt.fill_between(np.append(x1_list,x2_list[::-1]),np.append(z1_list,z2_list[::-1]),where=z2_list>=z1_list,facecolor='green',interpolate=True)# Represents the color between the two lines
plt.fill_between(np.append(x1_list,x2_list[::-1]),np.append(z1_list,z2_list[::-1]),where=z2_list<=z1_list,facecolor='red',interpolate=True)# Represents the color between the two lines
# Other options for drawing
plt.xticks (fontsize=10)
plt.yticks (fontsize=10)
plt.ylim ([-21.62, -21.46])
plt.grid(True)#Create a frame for the graph
plt.savefig("cm.png")
plt.show()
config=plt.figure()
Try global variables
Kunif, thank you for your reply.
© 2024 OneMinuteCode. All rights reserved.