-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQualifyingResult
59 lines (39 loc) · 1.65 KB
/
QualifyingResult
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import matplotlib.pyplot as plt
import pandas as pd
from timple.timedelta import strftimedelta
import fastf1
import fastf1.plotting
from fastf1.core import Laps
# we only want support for timedelta plotting in this example
fastf1.plotting.setup_mpl(mpl_timedelta_support=True, color_scheme=None, misc_mpl_mods=False)
session = fastf1.get_session(2023, 'British Grand Prix', 'Q')
session.load()
drivers = pd.unique(session.laps['Driver'])
print(drivers)
list_fastest_laps = list()
for drv in drivers:
drvs_fastest_lap = session.laps.pick_driver(drv).pick_fastest()
list_fastest_laps.append(drvs_fastest_lap)
fastest_laps = Laps(list_fastest_laps).sort_values(by='LapTime').reset_index(drop=True)
pole_lap = fastest_laps.pick_fastest()
fastest_laps['LapTimeDelta'] = fastest_laps['LapTime'] - pole_lap['LapTime']
print(fastest_laps[['Driver', 'LapTime', 'LapTimeDelta']])
team_colors = list()
for index, lap in fastest_laps.iterlaps():
color = fastf1.plotting.team_color(lap['Team'])
team_colors.append(color)
fig, ax = plt.subplots()
ax.barh(fastest_laps.index, fastest_laps['LapTimeDelta'],
color=team_colors, edgecolor='grey')
ax.set_yticks(fastest_laps.index)
ax.set_yticklabels(fastest_laps['Driver'])
# show fastest at the top
ax.invert_yaxis()
# draw vertical lines behind the bars
ax.set_axisbelow(True)
ax.xaxis.grid(True, which='major', linestyle='--', color='black', zorder=-1000)
# sphinx_gallery_defer_figures
lap_time_string = strftimedelta(pole_lap['LapTime'], '%m:%s.%ms')
plt.suptitle(f"{session.event['EventName']} {session.event.year} Qualifying\n"
f"Fastest Lap: {lap_time_string} ({pole_lap['Driver']})")
plt.show()