import os import matplotlib.pyplot as plt import numpy as np DATA_DIR = "data" # Find the newest summary CSV files = [f for f in os.listdir(DATA_DIR) if f.startswith("summary_") and f.endswith(".csv")] if not files: raise FileNotFoundError("No summary files found in 'data/'") latest_file = max(files, key=lambda f: os.path.getmtime(os.path.join(DATA_DIR, f))) filepath = os.path.join(DATA_DIR, latest_file) print(f"Plotting data from {filepath}") # Load CSV start_ms = [] end_ms = [] vals = [] # rows of [max, mean+std, mean, mean-std, min] with open(filepath, "r") as f: next(f) # skip header for line in f: parts = line.strip().split(",") if len(parts) != 7: continue s_ms, e_ms, *rest = parts start_ms.append(float(s_ms)) end_ms.append(float(e_ms)) vals.append([float(x) for x in rest]) vals = np.array(vals) # Time axis: relative seconds since first interval start start_ms = np.array(start_ms) # Plot plt.figure(figsize=(12, 6)) max_tot = vals[:, 1].mean() min_tot = vals[:, 3].mean() print(max_tot, min_tot) plt.scatter(start_ms, vals[:, 0], label="max", s=3) plt.scatter(start_ms, vals[:, 1], label="mean+std", s=3) plt.scatter(start_ms, vals[:, 2], label="mean", s=3) plt.scatter(start_ms, vals[:, 3], label="mean-std", s=3) plt.scatter(start_ms, vals[:, 4], label="min", s=3 ) plt.xlabel("Time since start (s)") plt.ylabel("Voltage summary (V)") plt.title(f"Voltage Summary ({latest_file})") plt.grid(True) plt.legend() plt.tight_layout() plt.show()