Visualize driver speed variations around the circuit with color-coded track maps
A speed comparison around a circuit identifies braking zones, acceleration areas, and flat-out sections. This tutorial shows how to create a color-coded track map. Color intensity along the racing line represents speed.
Create the plot with a background track line and color-coded speed overlay.
# Create visualization with FastF1 stylingfig, ax = plt.subplots(sharex=True, sharey=True, figsize=(12, 6.75))fig.suptitle(f'{weekend["EventName"]} {year} - {driver} - Speed', size=24, y=0.97, color='white')# Adjust margins and turn off axisplt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.12)ax.axis('off')ax.set_aspect('equal', adjustable='datalim')# Create background track lineax.plot(x, y, color='black', linestyle='-', linewidth=16, zorder=0)# Create a continuous norm to map from data points to colorsnorm = plt.Normalize(color.min(), color.max())lc = LineCollection(segments, cmap=colormap, norm=norm, linestyle='-', linewidth=5)# Set the values used for colormappinglc.set_array(color)# Add line segments to plotline = ax.add_collection(lc)
The native chart overlays every selected driver on a single axes. A shared color scale keeps colors comparable across drivers. The chart includes a driver legend and a horizontal speed colorbar. Pick the drivers with the drivers list. The default is the top-3 finishers:
import tif1# Overlay several drivers on one trackfig, ax = tif1.plot_multi_driver_speed_comparison( 2023, 'Bahrain', 'Q', drivers=['VER', 'PER', 'LEC'], cmap='plasma', save_path='multi_driver_speed_comparison.png', dpi=300,)plt.show()
The whole workflow above is wrapped in a single native function:
import tif1import matplotlib.pyplot as plt# One call: loads the session and overlays each driver's fastest lapfig, ax = tif1.plot_multi_driver_speed_comparison(2023, 'Bahrain', 'Q', drivers=['VER', 'PER', 'LEC'])plt.show()# Or save straight to a file# tif1.plot_multi_driver_speed_comparison(2023, 'Bahrain', 'Q', save_path='multi_driver_speed_comparison.png')