import tif1
import matplotlib.pyplot as plt
import numpy as np
session = tif1.get_session(2025, "Monza Grand Prix", "Qualifying")
ver = session.get_driver("VER")
fastest_lap = ver.get_fastest_lap()
telemetry = ver.get_lap(fastest_lap["LapNumber"].iloc[0]).telemetry
# Plot longitudinal acceleration
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(14, 10), sharex=True)
# Speed profile
ax1.plot(telemetry["Distance"], telemetry["Speed"], color="blue", linewidth=2)
ax1.set_ylabel("Speed (km/h)")
ax1.set_title("VER Fastest Lap - Speed and Acceleration")
ax1.grid(True, alpha=0.3)
# Acceleration (positive = accelerating, negative = braking)
ax2.plot(telemetry["Distance"], telemetry["AccelerationX"], color="red", linewidth=1.5)
ax2.axhline(0, color="black", linestyle="--", alpha=0.5)
ax2.fill_between(
telemetry["Distance"],
0,
telemetry["AccelerationX"],
where=(telemetry["AccelerationX"] > 0),
color="green",
alpha=0.3,
label="Acceleration"
)
ax2.fill_between(
telemetry["Distance"],
0,
telemetry["AccelerationX"],
where=(telemetry["AccelerationX"] < 0),
color="red",
alpha=0.3,
label="Braking"
)
ax2.set_xlabel("Distance (m)")
ax2.set_ylabel("Acceleration (m/s²)")
ax2.legend()
ax2.grid(True, alpha=0.3)
plt.tight_layout()
plt.show()