51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import os
|
|
import matplotlib.pyplot as plt
|
|
|
|
def plot_speed(log_path="output_this_run/simulation_time.log", output_png="output_this_run/simulation_speed.png"):
|
|
if not os.path.exists(log_path):
|
|
print(f"{log_path} not found.")
|
|
return
|
|
|
|
times = []
|
|
voltages = []
|
|
|
|
cumulative_time = 0.0
|
|
|
|
with open(log_path, "r") as f:
|
|
lines = f.readlines()
|
|
|
|
for line in lines:
|
|
if "Time" in line and "Voltage(V)" in line:
|
|
continue
|
|
parts = line.split()
|
|
if len(parts) >= 6:
|
|
try:
|
|
# Format: Time, Voltage(V), Step(V), Current(A), Iterations, TimeTaken(s)
|
|
voltage = float(parts[1])
|
|
time_taken = float(parts[5])
|
|
cumulative_time += time_taken
|
|
|
|
times.append(cumulative_time)
|
|
voltages.append(voltage)
|
|
except ValueError:
|
|
continue
|
|
|
|
if not times:
|
|
print("No valid data found in log.")
|
|
return
|
|
|
|
plt.figure(figsize=(10, 6))
|
|
plt.plot(times, voltages, marker='o', linestyle='-')
|
|
plt.xlabel("Cumulative Simulation Time (s)")
|
|
plt.ylabel("Voltage (V)")
|
|
plt.title("Simulation Voltage over Time")
|
|
plt.grid(True)
|
|
plt.savefig(output_png, dpi=300)
|
|
print(f"Plot saved to {output_png}")
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
log_file = sys.argv[1] if len(sys.argv) > 1 else "output_this_run/simulation_time.log"
|
|
out_file = sys.argv[2] if len(sys.argv) > 2 else "output_this_run/simulation_speed.png"
|
|
plot_speed(log_file, out_file)
|