@@ -34,55 +34,58 @@ def select_file():
3434 return tempdir
3535
3636
37- # Call the function to select the file
38- selected_file = str (select_file ())
37+ def main ():
38+ # Call the function to select the file
39+ selected_file = str (select_file ())
3940
40- # Print the selected file path
41- print (f"Selected file: { selected_file } " )
41+ # Print the selected file path
42+ print (f"Selected file: { selected_file } " )
4243
43- # Load data from CSV file
44+ # Load data from CSV file
4445
46+ # Set up the plot
47+ plt .style .use ('fivethirtyeight' )
48+ fig , axs = plt .subplots (3 , 1 , figsize = (9 , 12 ))
4549
46- # Set up the plot
47- plt .style .use ('fivethirtyeight' )
48- fig , axs = plt .subplots (3 , 1 , figsize = (9 , 12 ))
4950
51+ def animate (i ):
52+ # Reload data from CSV (in case it has changed)
53+ data = pd .read_csv (selected_file )
54+ x = data ['Time (s)' ]
55+ y1 = data ['Temperature (K)' ]
56+ y2 = data ['Current (A)' ]
5057
51- def animate (i ):
52- # Reload data from CSV (in case it has changed)
53- data = pd .read_csv (selected_file )
54- x = data ['Time (s)' ]
55- y1 = data ['Temperature (K)' ]
56- y2 = data ['Current (A)' ]
58+ # Clear previous plots
59+ for ax in axs :
60+ ax .clear ()
5761
58- # Clear previous plots
59- for ax in axs :
60- ax .clear ()
62+ # Update subplots
63+ axs [0 ].plot (x , y1 , label = 'T' , color = 'b' , linewidth = 0.8 )
64+ axs [0 ].scatter (x , y1 , color = 'b' )
65+ axs [0 ].set_title ('T vs time' , fontsize = 13 )
66+ axs [0 ].set_xlabel ('Time (s)' , fontsize = 13 )
67+ axs [0 ].set_ylabel ('Temperature (K)' , fontsize = 13 )
68+ axs [0 ].legend (loc = 'upper left' )
6169
62- # Update subplots
63- axs [0 ].plot (x , y1 , label = 'T' , color = 'b' , linewidth = 0.8 )
64- axs [0 ].scatter (x , y1 , color = 'b' )
65- axs [0 ].set_title ('T vs time' , fontsize = 13 )
66- axs [0 ].set_xlabel ('Time (s)' , fontsize = 13 )
67- axs [0 ].set_ylabel ('Temperature (K)' , fontsize = 13 )
68- axs [0 ].legend (loc = 'upper left' )
70+ axs [1 ].plot (x , y2 , label = 'I' , color = 'g' , linewidth = 0.8 )
71+ axs [1 ].scatter (x , y2 , color = 'g' )
72+ axs [1 ].set_title ('I vs time' , fontsize = 13 )
73+ axs [1 ].set_xlabel ('Time (s)' , fontsize = 13 )
74+ axs [1 ].set_ylabel ('Current (A)' , fontsize = 13 )
75+ axs [1 ].legend (loc = 'upper left' )
6976
70- axs [1 ].plot (x , y2 , label = 'I' , color = 'g ' , linewidth = 0.8 )
71- axs [1 ].scatter (x , y2 , color = 'g ' )
72- axs [1 ].set_title ('I vs time ' , fontsize = 13 )
73- axs [1 ].set_xlabel ('Time (s )' , fontsize = 13 )
74- axs [1 ].set_ylabel ('Current (A)' , fontsize = 13 )
75- axs [1 ].legend (loc = 'upper left' )
77+ axs [2 ].plot (y1 , y2 , label = 'I vs T ' , color = 'r ' , linewidth = 0.8 )
78+ axs [2 ].scatter (y1 , y2 , color = 'r ' )
79+ axs [2 ].set_title ('I vs T ' , fontsize = 13 )
80+ axs [2 ].set_xlabel ('Temperature (K )' , fontsize = 13 )
81+ axs [2 ].set_ylabel ('Current (A)' , fontsize = 13 )
82+ axs [2 ].legend (loc = 'upper left' )
7683
77- axs [2 ].plot (y1 , y2 , label = 'I vs T' , color = 'r' , linewidth = 0.8 )
78- axs [2 ].scatter (y1 , y2 , color = 'r' )
79- axs [2 ].set_title ('I vs T' , fontsize = 13 )
80- axs [2 ].set_xlabel ('Temperature (K)' , fontsize = 13 )
81- axs [2 ].set_ylabel ('Current (A)' , fontsize = 13 )
82- axs [2 ].legend (loc = 'upper left' )
8384
85+ ani = FuncAnimation (plt .gcf (), animate , interval = 1000 , cache_frame_data = False )
8486
85- ani = FuncAnimation (plt .gcf (), animate , interval = 1000 , cache_frame_data = False )
87+ plt .tight_layout ()
88+ plt .show ()
8689
87- plt . tight_layout ()
88- plt . show ()
90+ if __name__ == "__main__" :
91+ main ()
0 commit comments