Skip to main content
This tutorial demonstrates how to visualize lap time distributions for multiple drivers using violin plots combined with swarm plots. This visualization helps compare driver consistency, pace, and tire strategy across the field. Lap time distributions for top 10 finishers in the 2023 Azerbaijan Grand Prix

Setup

Load the Race Session

Filter Point Finishers

Get laps for the top 10 finishers (point-scoring positions) and filter out slow laps that would distort the visualization.

Get Finishing Order

To plot drivers by finishing order, extract their abbreviations in the correct sequence.

Create the Visualization

Combine violin plots (showing distributions) with swarm plots (showing individual lap times).

Enhance the Plot

Add labels, a title, and a clean layout to the plot.

Parameters

The native function exposes the same filters as parameters. n_drivers selects how many finishers to include (10 by default, matching the point finishers above). laptime_cutoff controls the per-driver outlier removal:
Drivers are always ordered by finishing position, and deleted and pit laps are always excluded.

Complete Example

The whole workflow above is wrapped in a single native function:

Understanding the Visualization

This dual-layer plot shows two kinds of information:

Violin Plot Layer

  • Shows the probability density of lap times for each driver
  • Wider sections indicate more laps at that pace
  • Shape reveals consistency and performance patterns
  • Symmetric shapes suggest consistent pace throughout the race

Swarm Plot Layer

  • Each dot represents an individual lap
  • Color indicates tire compound used
  • Horizontal spread shows the distribution of lap times
  • Vertical position shows the actual lap time

Insights from the Visualization

This visualization shows several aspects of race performance:
  1. Driver Consistency: Narrow distributions indicate consistent lap times
  2. Pace Comparison: Vertical position shows relative speed between drivers
  3. Tire Strategy: Compound colors reveal strategic choices
  4. Compound Performance: Compare lap times across different tire types
  5. Outliers: Individual slow laps are immediately visible

Analyzing Specific Patterns

Identifying the Fastest Driver

The driver with the lowest violin plot center typically had the best pace.

Spotting Tire Degradation

If a driver’s dots spread vertically within one compound, it suggests tire degradation.

Comparing Strategies

Drivers with more compound variety show different strategic approaches.

Customization Options

Adjust Plot Size and Style

Filter by Specific Compounds

Compare Different Sessions

Advanced Analysis

Statistical Summary

Extract statistical insights from the distributions:

Identify Consistency Leaders

Summary

This tutorial created a lap time distribution visualization that combines violin plots with swarm plots. The violin plots show the density of lap times. The swarm plots show individual laps. Together they give a statistical overview and per-lap detail for comparing driver performance and tire strategies across the field.

Driver Lap Times

Single driver lap time analysis.

Race Pace Analysis

Detailed pace comparison.

Tire Strategy

Tire compound analysis.

Plotting API

Plotting reference.
Last modified on September 3, 2026