.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gen_modules\examples_gallery\plot_team_pace_ranking.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gen_modules_examples_gallery_plot_team_pace_ranking.py: Team Pace Comparison ============================================= Rank team's race pace from the fastest to the slowest. .. GENERATED FROM PYTHON SOURCE LINES 5-18 .. code-block:: Python import seaborn as sns from matplotlib import pyplot as plt import fastf1 import fastf1.plotting # Load FastF1's dark color scheme fastf1.plotting.setup_mpl(mpl_timedelta_support=False, misc_mpl_mods=False, color_scheme='fastf1') .. GENERATED FROM PYTHON SOURCE LINES 19-22 Load the race session. Pick all quick laps (within 107% of fastest lap). For races with mixed conditions, pick_wo_box() is better. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python race = fastf1.get_session(2024, 1, 'R') race.load() laps = race.laps.pick_quicklaps() .. GENERATED FROM PYTHON SOURCE LINES 27-31 Convert the lap time column from timedelta to integer. This is a seaborn-specific modification. If plotting with matplotlib, set mpl_timedelta_support to true with plotting.setup_mpl. .. GENERATED FROM PYTHON SOURCE LINES 31-48 .. code-block:: Python transformed_laps = laps.copy() transformed_laps.loc[:, "LapTime (s)"] = laps["LapTime"].dt.total_seconds() # order the team from the fastest (lowest median lap time) tp slower team_order = ( transformed_laps[["Team", "LapTime (s)"]] .groupby("Team") .median()["LapTime (s)"] .sort_values() .index ) print(team_order) # make a color palette associating team names to hex codes team_palette = {team: fastf1.plotting.get_team_color(team, session=race) for team in team_order} .. rst-class:: sphx-glr-script-out .. code-block:: none Index(['Red Bull Racing', 'Ferrari', 'McLaren', 'Mercedes', 'Haas F1 Team', 'Aston Martin', 'Kick Sauber', 'Alpine', 'RB', 'Williams'], dtype='object', name='Team') .. GENERATED FROM PYTHON SOURCE LINES 49-70 .. code-block:: Python fig, ax = plt.subplots(figsize=(15, 10)) sns.boxplot( data=transformed_laps, x="Team", y="LapTime (s)", hue="Team", order=team_order, palette=team_palette, whiskerprops=dict(color="white"), boxprops=dict(edgecolor="white"), medianprops=dict(color="grey"), capprops=dict(color="white"), ) plt.title("2023 British Grand Prix") plt.grid(visible=False) # x-label is redundant ax.set(xlabel=None) plt.tight_layout() plt.show() .. image-sg:: /gen_modules/examples_gallery/images/sphx_glr_plot_team_pace_ranking_001.png :alt: 2023 British Grand Prix :srcset: /gen_modules/examples_gallery/images/sphx_glr_plot_team_pace_ranking_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.698 seconds) .. _sphx_glr_download_gen_modules_examples_gallery_plot_team_pace_ranking.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_team_pace_ranking.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_team_pace_ranking.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_team_pace_ranking.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_