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 colors (hex color code) to team names. (current season only)

fastf1.plotting.TEAM_TRANSLATE = {'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 = {'alexander albon': '#005aff', 'carlos sainz': '#ff8181', 'charles leclerc': '#dc0000', 'daniel ricciardo': '#ff8700', 'esteban ocon': '#70c2ff', 'fernando alonso': '#0090ff', 'george russell': '#24ffff', 'kevin magnussen': '#ffffff', 'lance stroll': '#25a617', 'lando norris': '#eeb370', 'lewis hamilton': '#00d2be', 'max verstappen': '#0600ef', 'mick schumacher': '#cacaca', 'nicholas latifi': '#012564', 'nico hulkenberg': '#2f9b90', 'pierre gasly': '#2b4562', 'sebastian vettel': '#006f62', 'sergio perez': '#716de2', 'valtteri bottas': '#900000', 'yuki tsunoda': '#356cac', 'zhou guanyu': '#500000'}

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

fastf1.plotting.DRIVER_TRANSLATE = {'ALB': 'alexander albon', 'ALO': 'fernando alonso', 'BOT': 'valtteri bottas', 'GAS': 'pierre gasly', 'HAM': 'lewis hamilton', 'HUL': 'nico hulkenberg', 'LAT': 'nicholas latifi', 'LEC': 'charles leclerc', 'MAG': 'kevin magnussen', 'MSC': 'mick schumacher', 'NOR': 'lando norris', 'OCO': 'esteban ocon', 'RIC': 'daniel ricciardo', 'RUS': 'george russell', 'SAI': 'carlos sainz', 'SER': 'sergio perez', 'STR': 'lance stroll', 'TSU': 'yuki tsunoda', 'VER': 'max verstappen', 'VET': 'sebastian vettel', 'ZHO': 'zhou guanyu'}

Mapping of driver names to theirs respective abbreviations.

fastf1.plotting.COLOR_PALETTE = ['#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 (='xaxis', optional) – can be ‘xaxis’ or ‘yaxis’

Returns

the modified axis instance