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 = {'alpine': '#fe86bc', 'aston martin': '#006f62', 'ferrari': '#dc0000', 'haas': '#ffffff', 'mclaren': '#ff8700', 'mercedes': '#00d2be', 'red bull': '#fcd700', 'sauber': '#00e701', 'visa rb': '#1634cb', 'williams': '#00a0dd'}

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', 'FER': 'ferrari', 'HAA': 'haas', 'MCL': 'mclaren', 'MER': 'mercedes', 'RBR': 'red bull', 'SAU': 'sauber', 'VRB': 'visa rb', 'WIL': 'williams'}

Mapping of team names to theirs respective abbreviations.

fastf1.plotting.DRIVER_COLORS: Dict[str, str] = {'alexander albon': '#005aff', 'ayumu iwasa': '#1e6176', 'carlos sainz': '#ff8181', 'charles leclerc': '#dc0000', 'daniel ricciardo': '#2b4562', 'esteban ocon': '#ff117c', 'felipe drugovich': '#2f9b90', 'fernando alonso': '#006f62', 'frederik vesti': '#00a6ff', 'george russell': '#24ffff', 'isack hadjar': '#1e6176', 'jack doohan': '#894667', 'jake dennis': '#907400', 'kevin magnussen': '#ffffff', 'lance stroll': '#00413b', 'lando norris': '#eeb370', 'lewis hamilton': '#00d2be', 'liam lawson': '#2b4562', 'logan sargeant': '#012564', 'max verstappen': '#fcd700', 'nico hulkenberg': '#cacaca', 'nyck de vries': '#1e3d61', 'oliver bearman': '#c40000', 'oscar piastri': '#ff8700', 'pato oward': '#ee6d3a', 'pierre gasly': '#fe86bc', 'robert shwartzman': '#9c0000', 'sergio perez': '#ffec7b', 'theo pourchaire': '#004601', 'valtteri bottas': '#00e701', 'yuki tsunoda': '#356cac', 'zak osullivan': '#1b3d97', 'zhou guanyu': '#008d01'}

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', 'IWA': 'ayumu iwasa', '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')
'#fcd700'
>>> driver_color('ver')
'#fcd700'
>>> driver_color('lec')
'#dc0000'

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

>>> driver_color('Max Verst')
'#fcd700'
>>> 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')
'#fcd700'
>>> team_color('redbull')
'#fcd700'
>>> team_color('Red')
'#fcd700'
>>> team_color('RBR')
'#fcd700'

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