.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "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_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-17 .. code-block:: Python import seaborn as sns from matplotlib import pyplot as plt import fastf1 import fastf1.plotting # The misc_mpl_mods option enables minor grid lines which clutter the plot fastf1.plotting.setup_mpl(misc_mpl_mods=False) .. GENERATED FROM PYTHON SOURCE LINES 18-19 Load the race session. .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: Python race = fastf1.get_session(2023, "Azerbaijan", 'R') race.load() .. GENERATED FROM PYTHON SOURCE LINES 24-26 Get all the laps for a single driver. Filter out slow laps as they distort the graph axis. .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: Python driver_laps = race.laps.pick_driver("ALO").pick_quicklaps().reset_index() .. GENERATED FROM PYTHON SOURCE LINES 30-34 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 34-47 .. 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.COMPOUND_COLORS, s=80, linewidth=0, legend='auto') .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 49-50 Make the plot more aesthetic. .. GENERATED FROM PYTHON SOURCE LINES 50-64 .. 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:: /examples_gallery/images/sphx_glr_plot_driver_laptimes_001.png :alt: Alonso Laptimes in the 2023 Azerbaijan Grand Prix :srcset: /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 6.029 seconds) .. _sphx_glr_download_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 ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_