.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/plot_speed_traces.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_speed_traces.py: Overlaying speed traces of two laps ====================================== Compare two fastest laps by overlaying their speed traces. .. GENERATED FROM PYTHON SOURCE LINES 6-21 .. code-block:: Python import matplotlib.pyplot as plt import fastf1.plotting # enable some matplotlib patches for plotting timedelta values and load # FastF1's default color scheme fastf1.plotting.setup_mpl(misc_mpl_mods=False) # load a session and its telemetry data session = fastf1.get_session(2021, 'Spanish Grand Prix', 'Q') session.load() .. GENERATED FROM PYTHON SOURCE LINES 22-23 First, we select the two laps that we want to compare .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: Python ver_lap = session.laps.pick_driver('VER').pick_fastest() ham_lap = session.laps.pick_driver('HAM').pick_fastest() .. GENERATED FROM PYTHON SOURCE LINES 28-30 Next we get the telemetry data for each lap. We also add a 'Distance' column to the telemetry dataframe as this makes it easier to compare the laps. .. GENERATED FROM PYTHON SOURCE LINES 30-34 .. code-block:: Python ver_tel = ver_lap.get_car_data().add_distance() ham_tel = ham_lap.get_car_data().add_distance() .. GENERATED FROM PYTHON SOURCE LINES 35-37 Finally, we create a plot and plot both speed traces. We color the individual lines with the driver's team colors. .. GENERATED FROM PYTHON SOURCE LINES 37-53 .. code-block:: Python rbr_color = fastf1.plotting.team_color('RBR') mer_color = fastf1.plotting.team_color('MER') fig, ax = plt.subplots() ax.plot(ver_tel['Distance'], ver_tel['Speed'], color=rbr_color, label='VER') ax.plot(ham_tel['Distance'], ham_tel['Speed'], color=mer_color, label='HAM') ax.set_xlabel('Distance in m') ax.set_ylabel('Speed in km/h') ax.legend() plt.suptitle(f"Fastest Lap Comparison \n " f"{session.event['EventName']} {session.event.year} Qualifying") plt.show() .. image-sg:: /examples_gallery/images/sphx_glr_plot_speed_traces_001.png :alt: Fastest Lap Comparison Spanish Grand Prix 2021 Qualifying :srcset: /examples_gallery/images/sphx_glr_plot_speed_traces_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.816 seconds) .. _sphx_glr_download_examples_gallery_plot_speed_traces.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_speed_traces.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_speed_traces.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_