Skip to main content
The 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()

Setup matplotlib for use with FastF1. This is optional but highly recommended for proper timedelta formatting and FastF1 color scheme. Parameters:
  • 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: True
  • color_scheme (str | None): Enable the FastF1 color scheme. Valid values: 'fastf1' or None. Default: None
Example:
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()

Get a team color based on a recognizable part of the team name. Parameters:
  • 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 obtained
  • colormap (str): One of 'default', 'fastf1', or 'official'. Default: 'default'
  • exact_match (bool): Match the identifier exactly (case-insensitive). Default: False
Returns: str - A hexadecimal RGB color code (e.g., '#FF0000') Example:

get_driver_color()

Get the color associated with a driver based on their abbreviation or name.
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.
Parameters:
  • identifier (str): Driver abbreviation (e.g., “VER”, “HAM”) or recognizable part of driver name
  • session (Session): The session for which the data should be obtained
  • colormap (str): One of 'default', 'fastf1', or 'official'. Default: 'default'
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: str - A hexadecimal RGB color code Example:

get_compound_color()

Get the compound color as hexadecimal RGB color code for a given tire compound. Parameters:
  • 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
Returns: str - A hexadecimal RGB color code Example:

Driver Styling

get_driver_style()

Get a plotting style that is unique for a driver, combining team colors with unique markers/line styles. This function simplifies creating unique and distinguishable visual styles for multiple drivers. Drivers from the same team get the same color but different line styles or markers. Parameters:
  • identifier (str): Driver abbreviation or recognizable part of driver name
  • style (str | Sequence[str] | Sequence[dict]): List of matplotlib plot arguments or custom style dictionaries
  • session (Session): The session for which the data should be obtained
  • colormap (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
Returns: dict - A dictionary of plot style arguments Built-in styling options: The function supports these matplotlib arguments: linestyle, marker, color, facecolor, edgecolor, and most other color-related arguments. Option 1: Built-in styles
Option 2: Custom styles with magic ‘auto’ color
Available built-in style variants:
  • Line styles: 'solid', 'dashed', 'dashdot', 'dotted'
  • Markers: 'x', 'o', '^', 'D'
Up to 4 drivers per team are supported with unique styles.

Color Mappings

get_driver_color_mapping()

Returns a dictionary mapping driver abbreviations to their team colors. Parameters:
  • session (Session): The session for which the data should be obtained
  • colormap (str): One of 'default', 'fastf1', or 'official'. Default: 'default'
Returns: dict[str, str] - Dictionary mapping driver abbreviations to RGB hex colors Example:

get_compound_mapping()

Returns a dictionary mapping compound names to their colors. Parameters:
  • session (Session): The session for which the data should be obtained
Returns: dict[str, str] - Dictionary mapping compound names to RGB hex colors Example:

Information Functions

get_team_name()

Get a full or shortened team name based on a recognizable part of the team name. Parameters:
  • identifier (str): A recognizable part of the team name
  • session (Session): The session for which the data should be obtained
  • short (bool): If True, return a shortened version. Default: False
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: str - The team name Example:

get_team_name_by_driver()

Get a team name based on a driver’s abbreviation or name. Parameters:
  • identifier (str): Driver abbreviation or recognizable part of driver name
  • session (Session): The session for which the data should be obtained
  • short (bool): If True, return a shortened version. Default: False
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: str - The team name Example:

get_driver_name()

Get a full driver name based on abbreviation or partial name. Parameters:
  • identifier (str): Driver abbreviation or recognizable part of driver name
  • session (Session): The session for which the data should be obtained
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: str - The full driver name Example:

get_driver_abbreviation()

Get a driver’s abbreviation based on their name or abbreviation. Parameters:
  • identifier (str): Recognizable part of driver name or abbreviation
  • session (Session): The session for which the data should be obtained
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: str - The driver abbreviation Example:

get_driver_names_by_team()

Get a list of full names of all drivers for a team in a session. Parameters:
  • identifier (str): A recognizable part of the team name
  • session (Session): The session for which the data should be obtained
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: list[str] - List of driver names Example:

get_driver_abbreviations_by_team()

Get a list of abbreviations of all drivers for a team in a session. Parameters:
  • identifier (str): A recognizable part of the team name
  • session (Session): The session for which the data should be obtained
  • exact_match (bool): Match the identifier exactly. Default: False
Returns: list[str] - List of driver abbreviations Example:

Listing Functions

list_team_names()

Returns a list of all team names in the session. Parameters:
  • session (Session): The session for which the data should be obtained
  • short (bool): If True, return shortened versions. Default: False
Returns: list[str] - List of team names Example:

list_driver_abbreviations()

Returns a list of all driver abbreviations in the session. Parameters:
  • session (Session): The session for which the data should be obtained
Returns: list[str] - List of driver abbreviations Example:

list_driver_names()

Returns a list of all full driver names in the session. Parameters:
  • session (Session): The session for which the data should be obtained
Returns: list[str] - List of driver names Example:

list_compounds()

Returns a list of all compound names for the season (not session-specific). Parameters:
  • session (Session): The session for which the season should be determined
Returns: list[str] - List of compound names Example:

Legend Utilities

add_sorted_driver_legend()

Adds a legend to the axis where drivers are grouped by team and ordered consistently with plot styles. This is a drop-in replacement for 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 object
  • session (Session): The session for which the data should be obtained
  • *args: Matplotlib legend args (same as ax.legend())
  • **kwargs: Matplotlib legend kwargs (same as ax.legend())
Returns: matplotlib.legend.Legend Example:

Configuration Functions

set_default_colormap()

Set the default colormap used for all color lookups. Parameters:
  • colormap (str): One of 'fastf1' or 'official'
Example:
The 'fastf1' colormap uses colors optimized for visualization, while 'official' uses the teams’ official brand colors.

override_team_constants()

Override the default team constants for a specific team. Changes only apply to the current session. This is intended for advanced users who want to customize team constants. Parameters:
  • identifier (str): A part of the team name (must match exactly, no fuzzy matching)
  • session (Session): The session for which the override should be applied
  • short_name (str | None): New value for the short name
  • official_color (str | None): New value for official color (hexadecimal RGB)
  • fastf1_color (str | None): New value for FastF1 color (hexadecimal RGB)
Example:

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
Switching color maps:

Fuzzy Matching

Most functions support fuzzy string matching for team and driver identifiers:
Set exact_match=True to disable fuzzy matching and require exact matches (case-insensitive).

Error Handling

Functions may raise the following exceptions:
  • FuzzyMatchError: When exact_match=False and the identifier couldn’t be matched with sufficient confidence
  • KeyError: When exact_match=True and no exact match exists
  • ValueError: When invalid parameters are provided (e.g., invalid colormap name)
Example: