Replies: 3 comments 3 replies
-
Sorry just to add what I'm trying to achive is each of the comparisons below. SQ1 RIC vs TSU SQ2 RIC vs TSU Many thanks! |
Beta Was this translation helpful? Give feedback.
-
Please, instead of just dumping a bunch of unformatted code here, please, make it a short example that shows the problem. Describe the issue you are having. Post any error message you may be getting. |
Beta Was this translation helpful? Give feedback.
-
Appologies. I will figure it out myself. Thanks for your reply |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm trying to see Miami Sprint Qualify plots between Ricciardo and Tsunoda without success with the code below as it's totally outside my ability!
Can anyone tell me the correct code, please?
import fastf1 as ff1
from fastf1 import plotting
from fastf1 import utils
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
import numpy as np
import pandas as pd
Enable the cache by providing the name of the cache folder
ff1.Cache.enable_cache('cache')
year, grand_prix, session = 2024, 'MIAMI', 'Sprint Qualifying'
quali = ff1.get_session(year, grand_prix, session)
quali.load() # This is new with Fastf1 v.2.2
This is how it used to be:
laps = quali.load_laps(with_telemetry=True)
driver_1, driver_2 = 'RIC', 'TSU'
sq1_laps, sq2_laps, sq3_laps = quali.laps.split_qualifying_sessions()
Laps can now be accessed through the .laps object coming from the session
laps_driver_1 = sq1_laps.pick_driver(driver_1)
laps_driver_2 = sq1_laps.pick_driver(driver_2)
Select the fastest lap
fastest_driver_1 = laps_driver_1.pick_fastest()
fastest_driver_2 = laps_driver_2.pick_fastest()
Retrieve the telemetry and add the distance column
telemetry_driver_1 = fastest_driver_1.get_telemetry().add_distance()
telemetry_driver_2 = fastest_driver_2.get_telemetry().add_distance()
Make sure we know the team name for coloring
team_driver_1 = fastest_driver_1['Team']
team_driver_2 = fastest_driver_2['Team']
Extract the delta time
delta_time, ref_tel, compare_tel = utils.delta_time(fastest_driver_1, fastest_driver_2)
plot_size = [15, 15]
plot_title = f"{quali.event.year} {quali.event.EventName} - {quali.name} - {driver_1} VS {driver_2}"
plot_ratios = [1, 3, 2, 1, 1, 2, 1]
plot_filename = plot_title.replace(" ", "") + ".png"
Make plot a bit bigger
plt.rcParams['figure.figsize'] = plot_size
Create subplots with different sizes
fig, ax = plt.subplots(7, gridspec_kw={'height_ratios': plot_ratios})
Set the plot title
ax[0].title.set_text(plot_title)
Delta line
ax[0].plot(ref_tel['Distance'], delta_time)
ax[0].axhline(0)
ax[0].set(ylabel=f"Gap to {driver_2} (s)")
Speed trace
ax[1].plot(telemetry_driver_1['Distance'], telemetry_driver_1['Speed'], label=driver_1, color='orange')
ax[1].plot(telemetry_driver_2['Distance'], telemetry_driver_2['Speed'], label=driver_2, color='green')
ax[1].set(ylabel='Speed')
ax[1].legend(loc="lower right")
Throttle trace
ax[2].plot(telemetry_driver_1['Distance'], telemetry_driver_1['Throttle'], label=driver_1, color='orange')
ax[2].plot(telemetry_driver_2['Distance'], telemetry_driver_2['Throttle'], label=driver_2, color='green')
ax[2].set(ylabel='Throttle')
Brake trace
ax[3].plot(telemetry_driver_1['Distance'], telemetry_driver_1['Brake'], label=driver_1, color='orange')
ax[3].plot(telemetry_driver_2['Distance'], telemetry_driver_2['Brake'], label=driver_2, color='green')
ax[3].set(ylabel='Brake')
Gear trace
ax[4].plot(telemetry_driver_1['Distance'], telemetry_driver_1['nGear'], label=driver_1, color='orange')
ax[4].plot(telemetry_driver_2['Distance'], telemetry_driver_2['nGear'], label=driver_2, color='green')
ax[4].set(ylabel='Gear')
RPM trace
ax[5].plot(telemetry_driver_1['Distance'], telemetry_driver_1['RPM'], label=driver_1, color='orange')
ax[5].plot(telemetry_driver_2['Distance'], telemetry_driver_2['RPM'], label=driver_2, color='green')
ax[5].set(ylabel='RPM')
DRS trace
ax[6].plot(telemetry_driver_1['Distance'], telemetry_driver_1['DRS'], label=driver_1, color='orange')
ax[6].plot(telemetry_driver_2['Distance'], telemetry_driver_2['DRS'], label=driver_2, color='green')
ax[6].set(ylabel='DRS')
ax[6].set(xlabel='Lap distance (meters)')
Hide x labels and tick labels for top plots and y ticks for right plots.
for a in ax.flat:
a.label_outer()
Store figure
plt.savefig(plot_filename, dpi=300)
plt.show()
Beta Was this translation helpful? Give feedback.
All reactions