Skip to content

API Reference

apply_style(color_scheme='fastf1', timedelta_support=True)

Apply a consistent Matplotlib style.

Uses FastF1's built-in styling (dark theme by default) and a few readability tweaks.

Source code in src/fastf1_analytics/plotting.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def apply_style(
    color_scheme: str | None = "fastf1",
    timedelta_support: bool = True,
) -> None:
    """Apply a consistent Matplotlib style.

    Uses FastF1's built-in styling (dark theme by default) and a few readability tweaks.
    """
    f1plot.setup_mpl(mpl_timedelta_support=timedelta_support, color_scheme=color_scheme)
    plt.rcParams.update(
        {
            # readability
            "figure.dpi": 160,
            "axes.titlesize": 14,
            "axes.labelsize": 12,
            "legend.frameon": False,
            "axes.grid": True,
            "grid.linestyle": "--",
            "grid.alpha": 0.25,
            # savefig defaults
            "savefig.bbox": "tight",
        }
    )

load_session(year, gp, session, *, cache='.fastf1')

Load a FastF1 session with optional local cache directory.

Source code in src/fastf1_analytics/session_loader.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
def load_session(
    year: int,
    gp: str,
    session: str,
    *,
    cache: str | None = ".fastf1",
) -> Any:
    """Load a FastF1 session with optional local cache directory."""
    if cache:
        cache_path = Path(cache)
        cache_path.mkdir(parents=True, exist_ok=True)  # ensure cache dir exists
        fastf1.Cache.enable_cache(str(cache_path))
    s = fastf1.get_session(year, gp, session)
    s.load()
    return s