Skip to content

Instantly share code, notes, and snippets.

@kiennguyen94
Created December 6, 2021 04:10
Show Gist options
  • Save kiennguyen94/a45ffe0523080544b522df11f7a43487 to your computer and use it in GitHub Desktop.
Save kiennguyen94/a45ffe0523080544b522df11f7a43487 to your computer and use it in GitHub Desktop.
Saudi Arabia Ham vs Ver incident
import fastf1 as ff1
from fastf1 import plotting
from matplotlib import pyplot as plt
plotting.setup_mpl()
ff1.Cache.enable_cache('/Volumes/My Passport/Documents/f1/cache') # optional but recommended
race = ff1.get_session(2021, 'Saudi Arabia Grand Prix', 'R')
laps = race.load_laps(with_telemetry=True)
ver = laps.pick_driver('VER')
ham = laps.pick_driver('HAM')
ver_car = ver.get_car_data()
ham_car = ham.get_car_data()
ver_lap37 = ver[ver['LapNumber'] == 37].get_car_data()
ver_lap36 = ver[ver['LapNumber'] == 36].get_car_data()
ham_lap37 = ham[ham['LapNumber'] == 37].get_car_data()
ham_lap36 = ham[ham['LapNumber'] == 36].get_car_data()
t36 = ver_lap36['Time']
v36 = ver_lap36['Speed']
t37 = ver_lap37['Time']
v37 = ver_lap37['Speed']
fig, ax = plt.subplots()
ax.plot(t36, v36, label='VER 36', color='#253cfa')
ax.plot(t37, v37, label='VER 37', color='#4e61fb')
t36 = ham_lap36['Time']
v36 = ham_lap36['Speed']
t37 = ham_lap37['Time']
v37 = ham_lap37['Speed']
ax.plot(t36, v36, label='HAM 36', color='#0ff0fa')
ax.plot(t37, v37, label='HAM 37', color='#6ff6fc')
t37 = ver_lap37['Time']
b37 = ver_lap37['Brake']
ax.plot(t37, b37, label='VER brake 37', color='#4e61fb')
t37 = ham_lap37['Time']
b37 = ham_lap37['Brake']
ax.plot(t37, b37, label='HAM brake 37', color='#6ff6fc')
t36 = ver_lap36['Time']
b36 = ver_lap36['Brake']
ax.plot(t36, b36, label='VER brake 36', color='#253cfa')
t36 = ham_lap36['Time']
b36 = ham_lap36['Brake']
ax.plot(t36, b36, label='HAM brake 36', color='#0ff0fa')
ax.set_xlabel('Time')
ax.set_ylabel('Speed [Km/h]')
ax.set_title('VER vs HAM')
ax.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment