Replies: 21 comments 10 replies
-
Yes, this probably was made with FastF1. But there's nothing special about this plot? It's just all the separate data channels and that's it. Regarding "old code" that is no longer working, please be more specific. What is not working? What error do you get? |
Beta Was this translation helpful? Give feedback.
-
When I'll get back home tomorrow I'll tell you the precise error.. But is this plot with all the lines in the same graphic? Is that possible? 😅On the x there's distance (no idea about how to get the line of "lap distance", if you can explain me pls 🙏). I made one plot for throttle, one for brake etc, this one seems all more precise / zoomed and everything in the same page (maybe I'm stupid and it's obtained just with photoshop) 🙂 |
Beta Was this translation helpful? Give feedback.
-
@ricky732 @theOehrly Do you mean this code? It doesn't work for me now as well. import fastf1 as ff1
import matplotlib.font_manager as fm
from fastf1 import plotting
from matplotlib import pyplot as plt
plotting.setup_mpl()
ff1.Cache.enable_cache('cache') # optional but recommended
year = 2021
wknd = 21
ses = 'R'
drv1 = 'VER'
drv2 = 'HAM'
weekend = ff1.get_session(year, wknd)
session = ff1.get_session(year, wknd, ses)
laps = session.load_laps(with_telemetry=True)
first_driver = laps.pick_driver(drv1)
first_driver_info = session.get_driver(drv1)
first_color = plotting.team_color(first_driver_info.team)
second_driver = laps.pick_driver(drv2)
second_driver_info = session.get_driver(drv2)
second_color = plotting.team_color(second_driver_info.team)
first_driver = laps.pick_driver(drv1).pick_fastest()
first_car = first_driver.get_car_data()
second_driver = laps.pick_driver(drv2).pick_fastest()
second_car = second_driver.get_car_data()
fig, ax = plt.subplots(6)
prop = fm.FontProperties(fname='F1.otf')
fig.suptitle(f'{first_driver_info.familyname} vs {second_driver_info.familyname} - Fastest lap - {weekend.name} {year} {ses}ualifying', fontproperties=prop, size=18)
l2, = ax[0].plot(second_car['Time'], second_car['Speed'], color=second_color)
l1, = ax[0].plot(first_car['Time'], first_car['Speed'], color=first_color)
ax[1].plot(second_car['Time'], second_car['RPM'], color=second_color)
ax[1].plot(first_car['Time'], first_car['RPM'], color=first_color)
ax[2].plot(second_car['Time'], second_car['nGear'], color=second_color)
ax[2].plot(first_car['Time'], first_car['nGear'], color=first_color)
ax[3].plot(second_car['Time'], second_car['Throttle'], color=second_color)
ax[3].plot(first_car['Time'], first_car['Throttle'], color=first_color)
ax[4].plot(second_car['Time'], second_car['Brake'], color=second_color)
ax[4].plot(first_car['Time'], first_car['Brake'], color=first_color)
ax[5].plot(second_car['Time'], second_car['DRS'], color=second_color)
ax[5].plot(first_car['Time'], first_car['DRS'], color=first_color)
ax[0].set_ylabel("Speed [km/h]")
ax[1].set_ylabel("RPM [#]")
ax[2].set_ylabel("Gear [#]")
ax[3].set_ylabel("Throttle [%]")
ax[4].set_ylabel("Brake [%]")
ax[5].set_ylabel("DRS")
ax[0].get_xaxis().set_ticklabels([])
ax[1].get_xaxis().set_ticklabels([])
ax[2].get_xaxis().set_ticklabels([])
ax[3].get_xaxis().set_ticklabels([])
ax[4].get_xaxis().set_ticklabels([])
fig.align_ylabels()
fig.legend((l1, l2), (f'{first_driver_info.familyname}', f'{second_driver_info.familyname}'), 'upper right')
plt.subplots_adjust(left=0.06 ,right=0.99, top=0.9, bottom=0.05)
plt.show() |
Beta Was this translation helpful? Give feedback.
-
This code seems good! What's the problem for not working? It was quite different from mine... But I am going to try it this afternoon! |
Beta Was this translation helpful? Give feedback.
-
This is the error Traceback (most recent call last):
File "C:\Users\Siddharth Tewari\Desktop\Formula 1\Fastest Laps\Telementry\Telemetry Comparison.py", line 1, in <module>
import fastf1 as ff1
File "C:\Users\Siddharth Tewari\AppData\Local\Programs\Python\Python39\lib\site-packages\fastf1\__init__.py", line 16, in <module>
from fastf1.core import get_session # noqa: F401
File "C:\Users\Siddharth Tewari\AppData\Local\Programs\Python\Python39\lib\site-packages\fastf1\core.py", line 58, in <module>
from fastf1 import api, ergast
File "C:\Users\Siddharth Tewari\AppData\Local\Programs\Python\Python39\lib\site-packages\fastf1\api.py", line 31, in <module>
import pandas as pd
File "C:\Users\Siddharth Tewari\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\__init__.py", line 51, in <module>
from pandas.core.api import (
File "C:\Users\Siddharth Tewari\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\api.py", line 14, in <module>
from pandas.core.algorithms import factorize, unique, value_counts
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 982, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 925, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1414, in find_spec
File "<frozen importlib._bootstrap_external>", line 1386, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1513, in find_spec
File "<frozen importlib._bootstrap_external>", line 142, in _path_stat |
Beta Was this translation helpful? Give feedback.
-
@ricky732 The distance data is easy to get. There was no example for this, but I've added one now: https://theoehrly.github.io/Fast-F1/examples_gallery/plot_speed_traces.html#sphx-glr-examples-gallery-plot-speed-traces-py @siddharth-tewari I'm pretty confident that that error is not caused by FastF1. |
Beta Was this translation helpful? Give feedback.
-
@theOehrly Any idea then why is it caused? I cannot understand it. Also is it fine that I sometimes used graphs made with fastf1 on Youtube and should I add the link to here in description? |
Beta Was this translation helpful? Give feedback.
-
@theOehrly Cleared the cache manually and now its working. Would you find checking this alternate code also? import fastf1 as ff1
import matplotlib.font_manager as fm
from fastf1 import plotting
from matplotlib import pyplot as plt
plotting.setup_mpl()
ff1.Cache.enable_cache('cache') # optional but recommended
year = 2021
wknd = 21
ses = 'R'
drv1 = 'VER'
drv2 = 'HAM'
weekend = ff1.get_session(year, wknd)
session = ff1.get_session(year, wknd, ses)
laps = session.load_laps(with_telemetry=True)
first_driver = drv1[drv1['LapNumber'] == 37].iloc[0]
first_driver_info = session.get_driver(drv1)
first_color = plotting.team_color(first_driver_info.team)
second_driver = drv1[drv1['LapNumber'] == 37].iloc[0]
second_driver_info = session.get_driver(drv2)
second_color = plotting.team_color(second_driver_info.team)
first_driver = laps.pick_driver(drv1).pick_fastest()
first_car = first_driver.get_car_data()
second_driver = laps.pick_driver(drv2).pick_fastest()
second_car = second_driver.get_car_data()
fig, ax = plt.subplots(6)
prop = fm.FontProperties(fname='F1.otf')
fig.suptitle(f'{first_driver_info.familyname} vs {second_driver_info.familyname} - Fastest lap - {weekend.name} {year} {ses}', fontproperties=prop, size=18)
l2, = ax[0].plot(second_car['Time'], second_car['Speed'], color=second_color)
l1, = ax[0].plot(first_car['Time'], first_car['Speed'], color=first_color)
ax[1].plot(second_car['Time'], second_car['RPM'], color=second_color)
ax[1].plot(first_car['Time'], first_car['RPM'], color=first_color)
ax[2].plot(second_car['Time'], second_car['nGear'], color=second_color)
ax[2].plot(first_car['Time'], first_car['nGear'], color=first_color)
ax[3].plot(second_car['Time'], second_car['Throttle'], color=second_color)
ax[3].plot(first_car['Time'], first_car['Throttle'], color=first_color)
ax[4].plot(second_car['Time'], second_car['Brake'], color=second_color)
ax[4].plot(first_car['Time'], first_car['Brake'], color=first_color)
ax[5].plot(second_car['Time'], second_car['DRS'], color=second_color)
ax[5].plot(first_car['Time'], first_car['DRS'], color=first_color)
ax[0].set_ylabel("Speed [km/h]")
ax[1].set_ylabel("RPM [#]")
ax[2].set_ylabel("Gear [#]")
ax[3].set_ylabel("Throttle [%]")
ax[4].set_ylabel("Brake [%]")
ax[5].set_ylabel("DRS")
ax[0].get_xaxis().set_ticklabels([])
ax[1].get_xaxis().set_ticklabels([])
ax[2].get_xaxis().set_ticklabels([])
ax[3].get_xaxis().set_ticklabels([])
ax[4].get_xaxis().set_ticklabels([])
fig.align_ylabels()
fig.legend((l1, l2), (f'{first_driver_info.familyname}', f'{second_driver_info.familyname}'), 'upper right')
plt.subplots_adjust(left=0.06 ,right=0.99, top=0.9, bottom=0.05)
plt.show() |
Beta Was this translation helpful? Give feedback.
-
@theOehrly I am stupid calling the last plot of that graphic "Distance".. It was the delta. What's the code to plot the delta? 🙂 And, last 2 questions, how to reduce line width / increase the size of the plot? Maybe I should check a tutorial about matplotlib for that.. And also, I used the "iloc" function to get a lap and print in the cmd all the laps of the drivers.. I know how to order them from the fastest to the slowest.. How to order them from the first to the last in the race? Example "lap 1, lap2, lap3" etc... |
Beta Was this translation helpful? Give feedback.
-
@ricky732 the code for the delta is in the documentation, see https://theoehrly.github.io/Fast-F1/utils.html. Changing the linewidth is fairly simple for example try I'm not sure what you mean by increase the size of the plot, |
Beta Was this translation helpful? Give feedback.
-
Yeah, exactly that! I'm going to try it now. Thank you so much. I've a double-monitor setup (3840x1080), so I just wanted to exploit not just 1920x1080 but even more if possible. |
Beta Was this translation helpful? Give feedback.
-
Ah I see, if you try |
Beta Was this translation helpful? Give feedback.
-
@theOllieS no, I've just tried & it's still 16:9 |
Beta Was this translation helpful? Give feedback.
-
@ricky732 There is a 'LapNumber' data column for determining the order of the laps. See the documentation at https://theoehrly.github.io/Fast-F1/core.html#fastf1.core.Laps Also, @theOllieS is correct, the "figure.figsize" adjustment does work. |
Beta Was this translation helpful? Give feedback.
-
@theOehrly yeah yeah, I found the LapNumber function. The problem is that the "figsize" does not work for me... My plotting is a simple window, there's no way to change the aspect:ratio, I did not manage to do it.. |
Beta Was this translation helpful? Give feedback.
-
Guys, do you know how to make a code to compare 2 drivers' laps and plot the map of the circuit with every corner / straight colored in a different way, based on who is the fastest in that section? It shouldn't be difficult... I mean for example if it's Lewis Vs. Max, the corner where Lewis is faster are cyan, the parts where max is faster are blue.. @theOehrly |
Beta Was this translation helpful? Give feedback.
-
Some of us are working on something like you describe, unfortunately it's a lot more complicated than what you might initially think. |
Beta Was this translation helpful? Give feedback.
-
Understood... |
Beta Was this translation helpful? Give feedback.
-
Guys, can someone tell me the way for creating an histogram that compares the speed-traps? And is there some more advanced graphic for the long-runs comparison for example during FP? (Not a simple plotting of lap times, that one I already have it.) @theOehrly |
Beta Was this translation helpful? Give feedback.
-
@ricky732 I made a program which gets data for all drivers of speedtraps. I don't know to plot so maybe you can try the rest. |
Beta Was this translation helpful? Give feedback.
-
@theOehrly I have an issue with team colours. Would you find checking it? Traceback (most recent call last):
File "C:\Users\Siddharth Tewari\Desktop\Formula 1\New folder\f1-data-analysis\program.py", line 193, in <module>
Comparison(2022, "Bahrain GP", "R", ["LEC", "VER"])
File "C:\Users\Siddharth Tewari\Desktop\Formula 1\New folder\f1-data-analysis\program.py", line 59, in __init__
self.drivers = [Driver(self.selected_session, driver)
File "C:\Users\Siddharth Tewari\Desktop\Formula 1\New folder\f1-data-analysis\program.py", line 59, in <listcomp>
self.drivers = [Driver(self.selected_session, driver)
File "C:\Users\Siddharth Tewari\Desktop\Formula 1\New folder\f1-data-analysis\program.py", line 21, in __init__
self.color = TEAM_COLORS[session.season][DRIVER_TEAM[session.season]
KeyError: 2022 |
Beta Was this translation helpful? Give feedback.
-
Can someone give me the algorithm to get a comparison like this between 2 laps of 2 drivers please? I think it was done with fast-F1, but I don't understand how... I've an issue also with team colors in plotting. Old code does not work anymore. Can you tell me the updated one? @theOehrly
Beta Was this translation helpful? Give feedback.
All reactions