The tif1.plotting module provides utilities for creating F1-themed visualizations with team and driver colors, compound colors, and matplotlib styling.
Setup
setup_mpl
Configure matplotlib with F1-themed styling.
Parameters:
color_scheme: Color scheme to use (currently only “fastf1” is supported)
misc_mpl_mods: Apply miscellaneous matplotlib modifications
mpl_timedelta_support: Enable timedelta support (compatibility parameter)
Example:
Color Functions
get_team_color
Get the official color for a team.
Parameters:
team: Team name (e.g., “Red Bull Racing”, “Ferrari”)
session: Optional session object (for future compatibility)
Returns:
- Hex color code (e.g., “#dc0000” for Ferrari)
Example:
get_driver_color
Get the color for a specific driver.
Parameters:
driver: 3-letter driver code (e.g., “VER”, “HAM”)
session: Optional session object
Returns:
Example:
get_driver_color_mapping
Get a complete mapping of driver codes to colors.
Parameters:
session: Optional session object to extract team colors for all drivers
Returns:
- Dictionary mapping driver codes to hex colors
Example:
Parameters:
compound: Compound name (e.g., “SOFT”, “MEDIUM”, “HARD”)
session: Optional session object
Returns:
Example:
get_compound_mapping
Get a complete mapping of compounds to colors.
Returns:
- Dictionary mapping compound names to hex colors
Styling Functions
get_driver_style
Build a driver style dictionary for plotting.
Parameters:
identifier: Driver code
style: Optional style specification (list of keys or dict)
session: Optional session object
Returns:
- Dictionary with color and linestyle
Example:
add_sorted_driver_legend
Add a legend with driver labels sorted alphabetically.
Parameters:
ax: Matplotlib axes object
session: Optional session object
Returns:
Example:
Color Constants
Team Colors
Compound Colors
Complete Example
Last modified on March 5, 2026