.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gen_modules/examples_gallery/plot_driver_laptimes.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_driver_laptimes.py: Driver Laptimes Scatterplot ============================== Plot a driver's lap times in a race, with color coding for the compounds. .. GENERATED FROM PYTHON SOURCE LINES 6-20 .. code-block:: Python import seaborn as sns from matplotlib import pyplot as plt import fastf1 import fastf1.plotting # Enable Matplotlib patches for plotting timedelta values and load # FastF1's dark color scheme fastf1.plotting.setup_mpl(mpl_timedelta_support=True, misc_mpl_mods=False, color_scheme='fastf1') .. GENERATED FROM PYTHON SOURCE LINES 21-22 Load the race session. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python race = fastf1.get_session(2023, "Azerbaijan", 'R') race.load() .. GENERATED FROM PYTHON SOURCE LINES 27-29 Get all the laps for a single driver. Filter out slow laps as they distort the graph axis. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python driver_laps = race.laps.pick_driver("ALO").pick_quicklaps().reset_index() .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/Fast-F1/Fast-F1/fastf1/core.py:3022: FutureWarning: pick_driver is deprecated and will be removed in a future release. Use pick_drivers instead. .. GENERATED FROM PYTHON SOURCE LINES 33-37 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. .. GENERATED FROM PYTHON SOURCE LINES 37-50 .. code-block:: Python fig, ax = plt.subplots(figsize=(8, 8)) sns.scatterplot(data=driver_laps, x="LapNumber", y="LapTime", ax=ax, hue="Compound", palette=fastf1.plotting.get_compound_mapping(session=race), s=80, linewidth=0, legend='auto') .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 52-53 Make the plot more aesthetic. .. GENERATED FROM PYTHON SOURCE LINES 53-67 .. code-block:: Python 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() .. image-sg:: /gen_modules/examples_gallery/images/sphx_glr_plot_driver_laptimes_001.png :alt: Alonso Laptimes in the 2023 Azerbaijan Grand Prix :srcset: /gen_modules/examples_gallery/images/sphx_glr_plot_driver_laptimes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.703 seconds) .. _sphx_glr_download_gen_modules_examples_gallery_plot_driver_laptimes.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_driver_laptimes.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_driver_laptimes.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_driver_laptimes.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_