Files
voltage/plot.py

31 lines
821 B
Python

import os
import matplotlib.pyplot as plt
import numpy as np
DATA_DIR = "data"
# Find the latest data file
files = [f for f in os.listdir(DATA_DIR) if f.startswith("voltages_") and f.endswith(".csv")]
if not files:
raise FileNotFoundError("No voltage data 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 data (skip header)
data = np.loadtxt(filepath, delimiter=",", skiprows=1)
times = data[:, 0]
voltages = data[:, 1]
# Plot
plt.figure(figsize=(10, 5))
plt.plot(times, voltages, marker='o', linestyle='-')
plt.xlabel("Time (s)")
plt.ylabel("Voltage (V)")
plt.title(f"Voltage Measurements ({latest_file})")
plt.grid(True)
plt.tight_layout()
plt.show()