Files

51 lines
1.4 KiB
Python

import matplotlib.pyplot as plt
import pandas as pd
import os
def plot_jam_log_combined(csv_path="jam_log.csv"):
"""
Liest jam_log.csv ein und plottet car_ratio und number_of_detections
gemeinsam in einem Plot mit zwei Y-Achsen.
"""
# Datei-Check
if not os.path.exists(csv_path):
print(f"Datei '{csv_path}' nicht gefunden.")
return
# CSV laden
df = pd.read_csv(csv_path)
print("loaded csv")
# Spalten prüfen
required_cols = {'car_ratio', 'jam_score', 'number_of_detections'}
if not required_cols.issubset(df.columns):
print(f"CSV muss folgende Spalten enthalten: {required_cols}")
return
x = df.index
car_ratio = df["car_ratio"]
detections = df["number_of_detections"]
# Plot mit zwei Y-Achsen
fig, ax1 = plt.subplots(figsize=(12, 6))
color1 = "tab:green"
ax1.set_xlabel("Frame")
ax1.set_ylabel("Car Ratio", color=color1)
ax1.plot(x, car_ratio, color=color1, label="Car Ratio", marker='o')
ax1.tick_params(axis='y', labelcolor=color1)
ax2 = ax1.twinx() # zweite Y-Achse
color2 = "tab:blue"
ax2.set_ylabel("Number of Detections", color=color2)
ax2.plot(x, detections, color=color2, label="Detections", marker='x')
ax2.tick_params(axis='y', labelcolor=color2)
# Titel und Legenden
plt.title("Car Ratio & Number of YOLO Detections over Time")
fig.tight_layout()
plt.grid(True)
plt.show()
plot_jam_log_combined()