Skip to content

Trying to create a scatter plot of the lap number a driver pits on versus qualifying position #452

Answered by Casper-Guo
laurence9899 asked this question in Q&A
Discussion options

You must be logged in to vote

I try to work with Pandas over Ergast where possible. Here is my implementation:

import numpy as np
import pandas as pd
import fastf1 as f
import fastf1.plotting as p
import matplotlib.pyplot as plt
import seaborn as sns

race = f.get_session(2021, 1, 'R')
quali = f.get_session(2021, 1, 'Q')
race.load()
quali.load()

p.setup_mpl()

race_laps = race.laps
in_laps = race_laps[~race_laps["PitInTime"].isna()]

# needed because you are working with old races
# p.driver_color won't be satisfactory
# many different implementations possible
def get_driver_color(driver:str) -> str:
    if driver in p.DRIVER_TRANSLATE:
        return p.driver_color(driver)
    else:
        return "#FFFFFF"

fig, ax…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@laurence9899
Comment options

Answer selected by laurence9899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants