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

Make the visualization more aesthetic and easier to read.

Complete Example

Here’s the full code in one block:

Understanding the Visualization

This dual-layer plot provides rich insights:

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 reveals several key 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 demonstrated how to create a comprehensive lap time distribution visualization that combines violin plots for density estimation with swarm plots for individual data points. This dual-layer approach provides both statistical overview and granular detail, making it ideal 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 March 6, 2026