Plotting - fastf1.plotting#

Helper functions for creating data plots.

fastf1.plotting provides optional functionality with the intention of making it easy to create nice plots.

This module offers mainly two things:
  • team names and colors

  • matplotlib mods and helper functions

Fast-F1 focuses on plotting data with matplotlib. Of course, you are not required to use matplotlib and you can use any other tool you like.

If you wish to use matplotlib, it is highly recommended to enable some helper functions by calling setup_mpl().

If you don’t want to use matplotlib, you can still use the team names and colors which are provided below.

Note

Plotting related functionality is likely to change in a future release.

fastf1.plotting.TEAM_COLORS = {'alfa romeo': '#900000', 'alphatauri': '#2b4562', 'alpine': '#0090ff', 'aston martin': '#006f62', 'ferrari': '#dc0000', 'haas': '#ffffff', 'mclaren': '#ff8700', 'mercedes': '#00d2be', 'red bull': '#0600ef', 'williams': '#005aff'}#

Mapping of team names to team colors (hex color codes). (current season only)

fastf1.plotting.TEAM_TRANSLATE: Dict[str, str] = {'AMR': 'aston martin', 'APN': 'alpine', 'APT': 'alphatauri', 'ARR': 'alfa romeo', 'FER': 'ferrari', 'HAA': 'haas', 'MCL': 'mclaren', 'MER': 'mercedes', 'RBR': 'red bull', 'WIL': 'williams'}#

Mapping of team names to theirs respective abbreviations.

fastf1.plotting.DRIVER_COLORS: Dict[str, str] = {'alexander albon': '#005aff', 'carlos sainz': '#ff8181', 'charles leclerc': '#dc0000', 'daniel ricciardo': '#2b4562', 'esteban ocon': '#70c2ff', 'felipe drugovich': '#2f9b90', 'fernando alonso': '#006f62', 'frederik vesti': '#00a6ff', 'george russell': '#24ffff', 'isack hadjar': '#1e6176', 'jack doohan': '#0075c2', 'jake dennis': '#9f99e2', 'kevin magnussen': '#ffffff', 'lance stroll': '#25a617', 'lando norris': '#eeb370', 'lewis hamilton': '#00d2be', 'liam lawson': '#2b4562', 'logan sargeant': '#012564', 'max verstappen': '#0600ef', 'nico hulkenberg': '#cacaca', 'nyck de vries': '#1e3d61', 'oliver bearman': '#c40000', 'oscar piastri': '#ff8700', 'pato oward': '#ee6d3a', 'pierre gasly': '#0090ff', 'robert shwartzman': '#9c0000', 'sergio perez': '#716de2', 'theo pourchaire': '#700000', 'valtteri bottas': '#900000', 'yuki tsunoda': '#356cac', 'zak osullivan': '#1b3d97', 'zhou guanyu': '#500000'}#

Mapping of driver names to driver colors (hex color codes). (current season only)

fastf1.plotting.DRIVER_TRANSLATE: Dict[str, str] = {'ALB': 'alexander albon', 'ALO': 'fernando alonso', 'BEA': 'oliver bearman', 'BOT': 'valtteri bottas', 'DEN': 'jake dennis', 'DEV': 'nyck de vries', 'DOO': 'jack doohan', 'DRU': 'felipe drugovich', 'GAS': 'pierre gasly', 'HAD': 'isack hadjar', 'HAM': 'lewis hamilton', 'HUL': 'nico hulkenberg', 'LAW': 'liam lawson', 'LEC': 'charles leclerc', 'MAG': 'kevin magnussen', 'NOR': 'lando norris', 'OCO': 'esteban ocon', 'OSU': 'zak osullivan', 'OWA': 'pato oward', 'PER': 'sergio perez', 'PIA': 'oscar piastri', 'POU': 'theo pourchaire', 'RIC': 'daniel ricciardo', 'RUS': 'george russell', 'SAI': 'carlos sainz', 'SAR': 'logan sargeant', 'SHW': 'robert shwartzman', 'STR': 'lance stroll', 'TSU': 'yuki tsunoda', 'VER': 'max verstappen', 'VES': 'frederik vesti', 'ZHO': 'zhou guanyu'}#

Mapping of driver names to theirs respective abbreviations.

fastf1.plotting.COMPOUND_COLORS: Dict[str, str] = {'HARD': '#f0f0ec', 'INTERMEDIATE': '#43b02a', 'MEDIUM': '#ffd12e', 'SOFT': '#da291c', 'TEST-UNKNOWN': '#434649', 'UNKNOWN': '#00ffff', 'WET': '#0067ad'}#

Mapping of tyre compound names to compound colors (hex color codes). (current season only)

fastf1.plotting.COLOR_PALETTE: List[str] = ['#FF79C6', '#50FA7B', '#8BE9FD', '#BD93F9', '#FFB86C', '#FF5555', '#F1FA8C']#

The default color palette for matplotlib plot lines in fastf1’s color scheme.

fastf1.plotting.setup_mpl(mpl_timedelta_support=True, color_scheme='fastf1', misc_mpl_mods=True)[source]#

Setup matplotlib for use with fastf1.

This is optional but, at least partly, highly recommended.

Parameters:
  • mpl_timedelta_support (bool) –

    Matplotlib itself offers very limited functionality for plotting timedelta values. (Lap times, sector times and other kinds of time spans are represented as timedelta.)

    Enabling this option will patch some internal matplotlib functions and register converters, formatters and locators for tick formatting. The heavy lifting for this is done by an external package called ‘Timple’. See https://github.com/theOehrly/Timple if you wish to customize the tick formatting for timedelta.

  • color_scheme (str, None) – This enables the Fast-F1 color scheme that you can see in all example images. Valid color scheme names are: [‘fastf1’, None]

  • misc_mpl_mods (bool) –

    This enables a collection of patches for the following mpl features:

    • .savefig (saving of figures)

    • .bar/.barh (plotting of bar graphs)

    • plt.subplots (for creating a nice background grid)

fastf1.plotting.driver_color(identifier)[source]#

Get a driver’s color from a driver name or abbreviation.

This function will try to find a matching driver for any identifier string that is passed to it. This involves case insensitive matching and partial string matching.

If you want exact string matching, you should use the DRIVER_COLORS dictionary directly, using DRIVER_TRANSLATE to convert abbreviations to team names if necessary.

Example:

>>> driver_color('charles leclerc')
'#dc0000'
>>> driver_color('max verstappen')
'#0600ef'
>>> driver_color('ver')
'#0600ef'
>>> driver_color('lec')
'#dc0000'

shortened driver names and typos can be dealt with
too (within reason)

>>> driver_color('Max Verst')
'#0600ef'
>>> driver_color('Charles')
'#dc0000'
Parameters:

identifier (str) – Abbreviation or uniquely identifying name of the driver.

Returns:

hex color code

Return type:

str

fastf1.plotting.team_color(identifier)[source]#

Get a team’s color from a team name or abbreviation.

This function will try to find a matching team for any identifier string that is passed to it. This involves case insensitive matching and partial string matching.

If you want exact string matching, you should use the TEAM_COLORS dictionary directly, using TEAM_TRANSLATE to convert abbreviations to team names if necessary.

Example:

>>> team_color('Red Bull')
'#0600ef'
>>> team_color('redbull')
'#0600ef'
>>> team_color('Red')
'#0600ef'
>>> team_color('RBR')
'#0600ef'

shortened team names, included sponsors and typos can be dealt with
too (within reason)

>>> team_color('Mercedes')
'#00d2be'
>>> team_color('Merc')
'#00d2be'
>>> team_color('Merecds')
'#00d2be'
>>> team_color('Mercedes-AMG Petronas F1 Team')
'#00d2be'
Parameters:

identifier (str) – Abbreviation or uniquely identifying name of the team.

Returns:

hex color code

Return type:

str

fastf1.plotting.lapnumber_axis(ax, axis='xaxis')[source]#

Set axis to integer ticks only.”

Parameters:
  • ax – matplotlib axis

  • axis – can be ‘xaxis’ or ‘yaxis’

Returns:

the modified axis instance