-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOC: add driver laptimes example (#369)
- Loading branch information
1 parent
e9832ee
commit 3ebeb28
Showing
3 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Driver Laptimes Scatterplot | ||
============================== | ||
Plot a driver's lap times in a race, with color coding for the compounds. | ||
""" | ||
|
||
import fastf1 | ||
import fastf1.plotting | ||
import seaborn as sns | ||
from matplotlib import pyplot as plt | ||
|
||
# The misc_mpl_mods option enables minor grid lines which clutter the plot | ||
fastf1.plotting.setup_mpl(misc_mpl_mods=False) | ||
|
||
############################################################################### | ||
# Load the race session. | ||
|
||
race = fastf1.get_session(2023, "Azerbaijan", 'R') | ||
race.load() | ||
|
||
############################################################################### | ||
# Get all the laps for a single driver. | ||
# Filter out slow laps as they distort the graph axis. | ||
|
||
driver_laps = race.laps.pick_driver("ALO").pick_quicklaps().reset_index() | ||
|
||
############################################################################### | ||
# Make the scattterplot using lap number as x-axis and lap time as y-axis. | ||
# Marker colors correspond to the compounds used. | ||
# Note: as LapTime is represented by timedelta, calling setup_mpl earlier | ||
# is required. | ||
|
||
fig, ax = plt.subplots(figsize=(8, 8)) | ||
|
||
sns.scatterplot(data=driver_laps, | ||
x="LapNumber", | ||
y="LapTime", | ||
ax=ax, | ||
hue="Compound", | ||
palette=fastf1.plotting.COMPOUND_COLORS, | ||
s=80, | ||
linewidth=0, | ||
legend='auto') | ||
# sphinx_gallery_defer_figures | ||
|
||
############################################################################### | ||
# Make the plot more aesthetic. | ||
ax.set_xlabel("Lap Number") | ||
ax.set_ylabel("Lap Time") | ||
|
||
# The y-axis increases from bottom to top by default | ||
# Since we are plotting time, it makes sense to invert the axis | ||
ax.invert_yaxis() | ||
plt.suptitle("Alonso Laptimes in the 2023 Azerbaijan Grand Prix") | ||
|
||
# Turn on major grid lines | ||
plt.grid(color='w', which='major', axis='both') | ||
sns.despine(left=True, bottom=True) | ||
|
||
plt.tight_layout() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,5 @@ requests>=2.28.1 | |
websockets>=10.3 | ||
seaborn | ||
plotly | ||
seaborn | ||
kaleido |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters