fastf1.plotting module provides functions for styling and visualizing Formula 1 data with matplotlib. It includes utilities for team colors, driver styling, compound colors, and matplotlib configuration.
Setup
setup_mpl()
mpl_timedelta_support(bool): Enable timedelta support for plotting lap times and sector times. Uses the Timple package to patch matplotlib for proper timedelta tick formatting. Default:Truecolor_scheme(str | None): Enable the FastF1 color scheme. Valid values:'fastf1'orNone. Default:None
The FastF1 color scheme applies a dark theme optimized for F1 data visualization, as seen in all example images in the documentation.
Color Functions
get_team_color()
identifier(str): A recognizable part of the team name (e.g., “Red Bull”, “Ferrari”, “Mercedes”)session(Session): The session for which the data should be obtainedcolormap(str): One of'default','fastf1', or'official'. Default:'default'exact_match(bool): Match the identifier exactly (case-insensitive). Default:False
'#FF0000')
Example:
get_driver_color()
This function returns the team color of the team the driver participated for in the session. There are no separate colors for each driver. Use
get_driver_style() to differentiate drivers of the same team.identifier(str): Driver abbreviation (e.g., “VER”, “HAM”) or recognizable part of driver namesession(Session): The session for which the data should be obtainedcolormap(str): One of'default','fastf1', or'official'. Default:'default'exact_match(bool): Match the identifier exactly. Default:False
get_compound_color()
compound(str): The name of the compound (e.g., “SOFT”, “MEDIUM”, “HARD”, “INTERMEDIATE”, “WET”)session(Session): The session for which the data should be obtained
Driver Styling
get_driver_style()
identifier(str): Driver abbreviation or recognizable part of driver namestyle(str | Sequence[str] | Sequence[dict]): List of matplotlib plot arguments or custom style dictionariessession(Session): The session for which the data should be obtainedcolormap(str): One of'default','fastf1', or'official'. Default:'default'additional_color_kws(list | tuple): Additional keys to treat as colors for the'auto'magic value. Default:()exact_match(bool): Match the identifier exactly. Default:False
linestyle, marker, color, facecolor, edgecolor, and most other color-related arguments.
Option 1: Built-in styles
- Line styles:
'solid','dashed','dashdot','dotted' - Markers:
'x','o','^','D'
Color Mappings
get_driver_color_mapping()
session(Session): The session for which the data should be obtainedcolormap(str): One of'default','fastf1', or'official'. Default:'default'
get_compound_mapping()
session(Session): The session for which the data should be obtained
Information Functions
get_team_name()
identifier(str): A recognizable part of the team namesession(Session): The session for which the data should be obtainedshort(bool): IfTrue, return a shortened version. Default:Falseexact_match(bool): Match the identifier exactly. Default:False
get_team_name_by_driver()
identifier(str): Driver abbreviation or recognizable part of driver namesession(Session): The session for which the data should be obtainedshort(bool): IfTrue, return a shortened version. Default:Falseexact_match(bool): Match the identifier exactly. Default:False
get_driver_name()
identifier(str): Driver abbreviation or recognizable part of driver namesession(Session): The session for which the data should be obtainedexact_match(bool): Match the identifier exactly. Default:False
get_driver_abbreviation()
identifier(str): Recognizable part of driver name or abbreviationsession(Session): The session for which the data should be obtainedexact_match(bool): Match the identifier exactly. Default:False
get_driver_names_by_team()
identifier(str): A recognizable part of the team namesession(Session): The session for which the data should be obtainedexact_match(bool): Match the identifier exactly. Default:False
get_driver_abbreviations_by_team()
identifier(str): A recognizable part of the team namesession(Session): The session for which the data should be obtainedexact_match(bool): Match the identifier exactly. Default:False
Listing Functions
list_team_names()
session(Session): The session for which the data should be obtainedshort(bool): IfTrue, return shortened versions. Default:False
list_driver_abbreviations()
session(Session): The session for which the data should be obtained
list_driver_names()
session(Session): The session for which the data should be obtained
list_compounds()
session(Session): The session for which the season should be determined
Legend Utilities
add_sorted_driver_legend()
ax.legend() that creates a more visually pleasing legend when using driver names or abbreviations as labels.
Parameters:
ax(matplotlib.axes.Axes): A Matplotlib Axes objectsession(Session): The session for which the data should be obtained*args: Matplotlib legend args (same asax.legend())**kwargs: Matplotlib legend kwargs (same asax.legend())
Configuration Functions
set_default_colormap()
colormap(str): One of'fastf1'or'official'
The
'fastf1' colormap uses colors optimized for visualization, while 'official' uses the teams’ official brand colors.override_team_constants()
identifier(str): A part of the team name (must match exactly, no fuzzy matching)session(Session): The session for which the override should be appliedshort_name(str | None): New value for the short nameofficial_color(str | None): New value for official color (hexadecimal RGB)fastf1_color(str | None): New value for FastF1 color (hexadecimal RGB)
Complete Visualization Example
Here’s a comprehensive example combining multiple plotting functions:Color Maps
FastF1 provides two color maps:FastF1 Colormap (default)
Colors optimized for data visualization with good contrast and distinction:- Designed for clarity in plots
- Works well with the FastF1 color scheme
- Default option for all color functions
Official Colormap
Official team brand colors:- Uses teams’ official brand colors
- May have less contrast in visualizations
- Activate with
colormap='official'parameter
Fuzzy Matching
Most functions support fuzzy string matching for team and driver identifiers:exact_match=True to disable fuzzy matching and require exact matches (case-insensitive).
Error Handling
Functions may raise the following exceptions:FuzzyMatchError: Whenexact_match=Falseand the identifier couldn’t be matched with sufficient confidenceKeyError: Whenexact_match=Trueand no exact match existsValueError: When invalid parameters are provided (e.g., invalid colormap name)
