Better makefile, plotting, saving the data, and cleanup
This commit is contained in:
31
plot.py
Normal file
31
plot.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
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")]
|
||||
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 voltage values
|
||||
voltages = np.loadtxt(filepath)
|
||||
|
||||
# Create time axis (in seconds)
|
||||
times = np.arange(len(voltages)) * (SAMPLE_INTERVAL_MS / 1000.0)
|
||||
|
||||
# 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()
|
||||
Reference in New Issue
Block a user