Minimized and with real time in the plots

This commit is contained in:
2025-12-20 20:58:07 +01:00
parent ce9b819b18
commit 552055fd0a
5 changed files with 29 additions and 74 deletions

13
plot.py
View File

@@ -3,10 +3,9 @@ import matplotlib.pyplot as plt
import numpy as np
DATA_DIR = "data"
SAMPLE_INTERVAL_MS = 300 # time between measurements in milliseconds
# Find the latest data file
files = [f for f in os.listdir(DATA_DIR) if f.startswith("voltages_") and f.endswith(".txt")]
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/'")
@@ -14,11 +13,10 @@ 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 voltage values
voltages = np.loadtxt(filepath)
# Create time axis (in seconds)
times = np.arange(len(voltages)) * (SAMPLE_INTERVAL_MS / 1000.0)
# Load CSV data (skip header)
data = np.loadtxt(filepath, delimiter=",", skiprows=1)
times = data[:, 0]
voltages = data[:, 1]
# Plot
plt.figure(figsize=(10, 5))
@@ -29,3 +27,4 @@ plt.title(f"Voltage Measurements ({latest_file})")
plt.grid(True)
plt.tight_layout()
plt.show()