@@ -31,55 +31,55 @@ def select_file():
3131 return tempdir
3232
3333
34+ def live_plot_from_csv (selected_file ):
35+ # Set up the plot
36+ plt .style .use ('fivethirtyeight' )
37+ fig , axs = plt .subplots (3 , 1 , figsize = (9 , 12 ))
38+
39+ def animate (i ):
40+ # Reload data from CSV (in case it has changed)
41+ data = pd .read_csv (selected_file )
42+ x = data ['Time (s)' ]
43+ y1 = data ['Temperature (K)' ]
44+ y2 = data ['Voltage (V)' ]
45+
46+ # Clear previous plots
47+ for ax in axs :
48+ ax .clear ()
49+
50+ # Update subplots
51+ axs [0 ].plot (x , y1 , label = 'T' , color = 'b' , linewidth = 0.8 )
52+ axs [0 ].scatter (x , y1 , color = 'b' )
53+ axs [0 ].set_title ('V vs time' , fontsize = 13 )
54+ axs [0 ].set_xlabel ('Time (s)' , fontsize = 13 )
55+ axs [0 ].set_ylabel ('Temperature (K)' , fontsize = 13 )
56+ axs [0 ].legend (loc = 'upper left' )
57+
58+ axs [1 ].plot (x , y2 , label = 'V' , color = 'g' , linewidth = 0.8 )
59+ axs [1 ].scatter (x , y2 , color = 'g' )
60+ axs [1 ].set_title ('V vs time' , fontsize = 13 )
61+ axs [1 ].set_xlabel ('Time (s)' , fontsize = 13 )
62+ axs [1 ].set_ylabel ('Voltage (V)' , fontsize = 13 )
63+ axs [1 ].legend (loc = 'upper left' )
64+
65+ axs [2 ].plot (y1 , y2 , label = 'V vs T' , color = 'r' , linewidth = 0.8 )
66+ axs [2 ].scatter (y1 , y2 , color = 'r' )
67+ axs [2 ].set_title ('V vs T' , fontsize = 13 )
68+ axs [2 ].set_xlabel ('Temperature (K)' , fontsize = 13 )
69+ axs [2 ].set_ylabel ('Voltage (V)' , fontsize = 13 )
70+ axs [2 ].legend (loc = 'upper left' )
71+
72+ ani = FuncAnimation (plt .gcf (), animate , interval = 1000 , cache_frame_data = False )
73+
74+ plt .tight_layout ()
75+ plt .show ()
76+
77+
3478# Call the function to select the file
3579selected_file = str (select_file ())
3680
3781# Print the selected file path
3882print (f"Selected file: { selected_file } " )
3983
4084# Load data from CSV file
41-
42-
43- # Set up the plot
44- plt .style .use ('fivethirtyeight' )
45- fig , axs = plt .subplots (3 , 1 , figsize = (9 , 12 ))
46-
47-
48- def animate (i ):
49- # Reload data from CSV (in case it has changed)
50- data = pd .read_csv (selected_file )
51- x = data ['Time (s)' ]
52- y1 = data ['Temperature (K)' ]
53- y2 = data ['Voltage (V)' ]
54-
55- # Clear previous plots
56- for ax in axs :
57- ax .clear ()
58-
59- # Update subplots
60- axs [0 ].plot (x , y1 , label = 'T' , color = 'b' , linewidth = 0.8 )
61- axs [0 ].scatter (x , y1 , color = 'b' )
62- axs [0 ].set_title ('V vs time' , fontsize = 13 )
63- axs [0 ].set_xlabel ('Time (s)' , fontsize = 13 )
64- axs [0 ].set_ylabel ('Temperature (K)' , fontsize = 13 )
65- axs [0 ].legend (loc = 'upper left' )
66-
67- axs [1 ].plot (x , y2 , label = 'V' , color = 'g' , linewidth = 0.8 )
68- axs [1 ].scatter (x , y2 , color = 'g' )
69- axs [1 ].set_title ('V vs time' , fontsize = 13 )
70- axs [1 ].set_xlabel ('Time (s)' , fontsize = 13 )
71- axs [1 ].set_ylabel ('Voltage (V)' , fontsize = 13 )
72- axs [1 ].legend (loc = 'upper left' )
73-
74- axs [2 ].plot (y1 , y2 , label = 'V vs T' , color = 'r' , linewidth = 0.8 )
75- axs [2 ].scatter (y1 , y2 , color = 'r' )
76- axs [2 ].set_title ('V vs T' , fontsize = 13 )
77- axs [2 ].set_xlabel ('Temperature (K)' , fontsize = 13 )
78- axs [2 ].set_ylabel ('Voltage (V)' , fontsize = 13 )
79- axs [2 ].legend (loc = 'upper left' )
80-
81-
82- ani = FuncAnimation (plt .gcf (), animate , interval = 1000 , cache_frame_data = False )
83-
84- plt .tight_layout ()
85- plt .show ()
85+ live_plot_from_csv (selected_file )
0 commit comments