track X,Y coordiantes #157
Replies: 2 comments 7 replies
-
I have a code which makes the track layout photo. Hope it helps but only problem is that it uses "Session.load_laps" which will be deprecated. You need to fix it. import fastf1 as ff1
import matplotlib.font_manager as fm
from fastf1 import plotting
from matplotlib import pyplot as plt
from labellines import labelLine, labelLines
def add_arrow(line, position=None, start_ind=None, direction='right', size=15, color=None):
if color is None:
color = line.get_color()
xdata = line.get_xdata()
ydata = line.get_ydata()
if position is None:
position = xdata.mean()
# find closest index
if start_ind is None:
start_ind = len(xdata) // 2
if direction == 'right':
end_ind = start_ind + 1
else:
end_ind = start_ind - 1
line.axes.annotate('',
xytext=(xdata[start_ind], ydata[start_ind]),
xy=(xdata[end_ind], ydata[end_ind]),
arrowprops=dict(arrowstyle="-|>", color=color),
size=size
)
ff1.Cache.enable_cache('/cache') # optional but recommended
year = 2022
wknd = 1
ses = 'R'
weekend = ff1.get_session(year, wknd)
session = ff1.get_session(year, wknd, ses)
laps = session.load_laps(with_telemetry=True)
lap = laps.pick_fastest()
# Track with sectors
sec1 = lap.Sector1Time
sec2 = lap.Sector1Time+lap.Sector2Time
sec3 = lap.Sector1Time+lap.Sector2Time+lap.Sector3Time
times = lap.telemetry[['Time', 'X', 'Y']]
rslt1 = times[(times['Time'] <= sec1)]
rslt2 = times[(times['Time'] <= sec2) & (times['Time'] > sec1)]
rslt3 = times[(times['Time'] <= sec3) & (times['Time'] > sec2)]
fig2, ax2 = plt.subplots(figsize=(12, 6.75))
prop = fm.FontProperties(fname='F1.otf')
fig2.suptitle(f'{weekend.name} {year}', fontproperties=prop, size=24, y=0.97)
ax2.plot(lap.telemetry['X'], lap.telemetry['Y'], color='black', linestyle='-', linewidth=16)
line1 = ax2.plot(rslt1['X'], rslt1['Y'], label='sector 1', color='red', linestyle='-', linewidth=3)[0]
line2 = ax2.plot(rslt2['X'], rslt2['Y'], label='sector 2', color='cornflowerblue', linestyle='-', linewidth=3)[0]
line3 = ax2.plot(rslt3['X'], rslt3['Y'], label='sector 3', color='gold', linestyle='-', linewidth=3)[0]
add_arrow(line1, start_ind=1, size=20, color='white')
labelLines(plt.gca().get_lines(), backgroundcolor='black', fontsize=8, zorder=2.5)
plt.subplots_adjust(left=0.01 ,right=0.99, top=0.9, bottom=0.01)
plt.axis('off')
plt.show() |
Beta Was this translation helpful? Give feedback.
-
thanks for your reply, for this, i am able to draw the track based on X,Y,Z of the driver in any lap wanted, but I was looking to get the tracks X,Y,Z in any way/ from any API or site, so I would be able to animate the car on that track using the X,Y,Z of the car and X,Y,Z of the track. |
Beta Was this translation helpful? Give feedback.
-
we can get the car's position ['X',"Y','Z'] from the telemetry, but what about the track coordinates so we can plot the track and the car's position with respect to the track.
Beta Was this translation helpful? Give feedback.
All reactions