Chapter 25 Exercises — F1 Data Visualization
Difficulty: ⭐ concept check · ⭐⭐ calculation or short script · ⭐⭐⭐ analysis and judgment · ⭐⭐⭐⭐ open-ended project
All data come from the book's snapshot (OpenF1 2023–2026 R21, Jolpica-F1 1950–2026). Scripts run offline from data/processed/. Never turn on allow_fetch. Start each script from the chapter's header (Chapter 25, code/01_question_first.py) and from boxbox import viz.
Part A — Concepts ⭐
A1. A gap-to-leader chart of the 2025 Japanese GP shows Verstappen 11.033 s behind the leader on lap 22. In one sentence, explain what happened on track, and name the design choice that created the misleading picture.
Answer
Verstappen pitted, and Antonelli, who had not stopped yet, led laps 22–31. The chart's reference (the car leading at each lap) changed, so Verstappen's line moved although no car took time from him on track.
A2. List the three references this chapter uses for gap charts and race traces, and give one situation in which each one misleads.
Answer
Leader: misleads during stop cycles, when the leader changes. Winner's average pace (race trace): misleads in safety-car races, because the average absorbs the slow laps and tilts every line. A fixed car: misleads if that car retires or is lapped, or if the reader assumes it is the leader. Name the reference car in the axis label.
A3. Which of these quantities may be drawn as bars starting at zero, and which may not? Lap time; gap to pole; number of pit stops; top speed; time lost in a pit stop; track temperature.
Answer
May: gap to pole, number of stops, pit-stop time loss (each has a meaningful zero). Should not: lap time, top speed, track temperature. Draw them as points on a window, or convert them to differences first.
A4. Why is a rainbow colour scale (jet) a poor choice for a track map coloured by speed? Use the word "lightness" in your answer.
Answer
Jet's lightness rises and then falls along the scale (OKLab L from 0.27 up to 0.95 and back to 0.38; it decreases in 108 of 255 steps). The eye ranks marks by lightness, so middle speeds look the most prominent and the fastest straights look dark. The order is lost in greyscale and for colour-blind readers.
A5. What is the difference between a sequential, a diverging and a categorical colour scale? Give an F1 example of each.
Answer
Sequential: one direction of magnitude, light to dark (speed on a track map). Diverging: two directions from a meaningful middle, two hues meeting at a neutral grey (who gains where, NOR versus VER). Categorical: identity with no order (teams; compounds).
A6. Two team-mates share an identical colour. Name three cues that can separate them without changing the team colour.
Answer
Line style (solid and dashed, the toolkit's driver_styles rule), marker shape, and direct labels at the line ends. Panels (small multiples) are a fourth option.
A7. Why must every interactive chart in the book have a static fallback and a table view?
Answer
Printed and PDF readers cannot run JavaScript, and screen-reader users cannot use hover tooltips. A tooltip may add detail, but it must never be the only way to read a value.
A8. Figure 25.7b shades a band of ±0.05 s around zero in the delta panel. Where does that number come from, and what does it mean that 65.1 % of the trace lies inside it?
Answer
It is Chapter 19's working rule, based on the telemetry delta's measured error at the official sector lines (median 0.024 s, 90th percentile 0.077 s, over 564 predictions). For 65 % of the lap the cumulative gap between VER and NOR is smaller than the instrument can vouch for.
A9. A chart's title reads "Lap times, 2025 Japanese GP". Rewrite it as a finding, using one number from this chapter, and say why the rewrite helps a reader who looks at the chart for only two seconds.
Answer
For example: "Norris matched Verstappen lap for lap after the stops (median −0.013 s) but never got within 1 s." A reader who stops at the title still leaves with the finding and the evidence, and a reader who studies the chart knows what to check it against.
A10. What is "focus and context", and why is the context drawn at all?
Answer
The cars the story is about are drawn in colour, thick, with direct labels, and every other car is drawn thin and grey underneath. The grey field is the traffic: it shows how crowded the order was and how many cars a driver passed, which an empty background would hide.
Part B — Calculations & Physics ⭐⭐
B1. Contrast in light and dark mode. McLaren's 2025 OpenF1 colour is #FF8000. Using the WCAG formula from 25.2, its relative luminance is about 0.367. (a) Compute its contrast on white ($Y = 1$). (b) Its contrast on a dark chart background #1A1A19 ($Y \approx 0.0103$). (c) Which background suits an orange line?
Solution
(a) (1.00 + 0.05) / (0.367 + 0.05) = 2.52:1, below the 3:1 target. (b) (0.367 + 0.05) / (0.0103 + 0.05) = 6.92:1. (c) The dark background. On white, the orange line needs help: a darker variant (Case Study 2), a thicker line or a direct label. In practice you design light and dark versions separately and check each one.
B2. Two blues. In 2026, Red Bull #4781D7 and Williams #1868DB are ΔE = 8.0 apart for normal vision, 7.5 under deuteranopia and 8.0 under protanopia. Classify the pair with the chapter's thresholds and say what Figure 25.11b did about it.
Solution
The worst case is 7.5, which is in the 6–8 band, and normal vision is below 15, so the verdict is "needs a second cue". In Figure 25.11b Verstappen is solid and Sainz (Williams's second driver) is dashed, and both lines end in direct labels.
B3. The distortion of a truncated bar. In Figure 25.5B the axis starts at 90.9 s. Russell's median lap was 91.237 s and Piastri's 90.973 s. (a) What is the ratio of their bar lengths? (b) The ratio of their lap times? (c) The distortion factor, (bar ratio − 1) / (data ratio − 1)?
Solution
(a) (91.237 − 90.9) / (90.973 − 90.9) = 0.337 / 0.073 = 4.62. (b) 91.237 / 90.973 = 1.0029. (c) (4.62 − 1) / (1.0029 − 1) ≈ 1,250. The chart exaggerates their difference about twelve hundred times. The honest version draws the gap, 0.264 s, from a zero at the fastest car.
B4. Telemetry resolution as time. The median sample interval on the 2025 Suzuka pole lap is 0.24 s. (a) How far does a car travel between samples at 300 km/h and at 77 km/h (the hairpin minimum)? (b) If two laps are misaligned by 10 m, how big an error in the delta does that create at each speed?
Solution
(a) 300 km/h = 83.3 m/s, so 20.0 m. 77 km/h = 21.4 m/s, so 5.1 m. (b) Time error = distance error / speed: 10 / 83.3 = 0.12 s at 300 km/h, and 10 / 21.4 = 0.47 s at the hairpin. That is why a uniform alignment can put a spurious tenth or two of delta at the slowest corner (Chapter 19's −0.258 s spike), and why sector anchoring matters most there.
B5. What the winner's average hides. In the 2026 Las Vegas race trace against the winner's average pace (Figure 25.16a), Verstappen is at −1.9 s after lap 1 and −112.1 s after lap 18. (a) Estimate how much faster his green laps were than the winner's average lap, per lap. (b) Explain in one sentence why this is not "pace".
Solution
(a) (−112.1 − (−1.9)) / 17 laps = −6.48 s per lap: every green lap was about 6.5 s quicker than the race-average lap. (b) The race average includes seven safety-car laps, so it is far slower than any racing lap. The slope measures the reference, not a difference between cars.
B6. Darken to legibility. viz.darken_to_contrast("#27F4D2") (Mercedes, 2024–25) returns #0AA78F with contrast 3.03:1, a shift of ΔE 21.8 from the original. McLaren #FF8000 becomes #E87507 (ΔE 5.1). Why does Mercedes have to move four times as far as McLaren to reach the same contrast?
Solution
Mercedes starts much lighter (OKLab L ≈ 0.87, contrast 1.40:1) than McLaren (L ≈ 0.73, contrast 2.52:1). Contrast on white depends almost entirely on lightness, so the lighter colour has to drop much further. A shift of ΔE 21.8 is large enough that the darkened teal may no longer read as "Mercedes" to fans, which is the trade-off Case Study 2 measures.
B7. Compound colours under deuteranopia. The toolkit's SOFT #DA291C and INTERMEDIATE #43B02A are ΔE 34.9 apart for normal vision and 8.0 under deuteranopia. HARD #F0F0EC has contrast 1.14:1 on white and MEDIUM #FFD12E 1.46:1. Which compound pair is the CVD risk, and which compound is the contrast risk? What does viz.strategy_chart add for each?
Solution
SOFT versus INTERMEDIATE is the CVD risk: it is on the 8.0 threshold under deuteranopia, a classic red–green pair. HARD (and to a lesser degree MEDIUM) is the contrast risk on white. strategy_chart prints a letter (S, M, H, I, W) on every stint long enough to hold one, and draws a dark edge around HARD bars. Neither cue depends on colour vision.
B8. Run the deuteranopia matrix by hand. Ferrari's 2025 red #E80020 linearises to (R, G, B) = (0.807, 0.000, 0.014). Aston Martin's green #229971 linearises to (0.016, 0.319, 0.165). Apply the first two rows of the deuteranopia matrix from 25.2 (0.367, 0.861, −0.228 and 0.280, 0.673, 0.047) to each colour. What do you notice about the simulated red and green channels of the two colours, and what does that predict about their ΔE?
Solution
Ferrari: R′ = 0.367 × 0.807 + 0.861 × 0 − 0.228 × 0.014 = 0.293; G′ = 0.280 × 0.807 + 0.673 × 0 + 0.047 × 0.014 = 0.227. Aston Martin: R′ = 0.367 × 0.016 + 0.861 × 0.319 − 0.228 × 0.165 = 0.242; G′ = 0.280 × 0.016 + 0.673 × 0.319 + 0.047 × 0.165 = 0.227. The G′ values are identical and R′ differs by only 0.05, so after simulation the two colours differ mainly in the blue channel (0.004 against 0.174). That predicts a large drop in ΔE, and the code gives 33.8 to 10.0. They survive as a pair only because the green carries some blue and the red carries none. Their OKLab lightness is almost equal (0.586 and 0.610), so lightness does not help.
Part C — Data & Code ⭐⭐–⭐⭐⭐
C1. Analyze this session ⭐⭐. 2024 Japanese GP, Race. Draw (a) the default plots.gap_chart and (b) a gap-to-winner chart for P2 and P3 with viz.pair_gaps, the stop window greyed. Report the lap range on which the leader was not the eventual winner, and the minimum gap of P2 to the winner on racing laps. Expected shape: two PNGs, a printed list of leader runs ("leader X: laps a–b"), and three numbers (min, median, max gap). Note that 2024 Japan had a red flag on lap 1, which corrupts lap 1's timestamps (toolkit README §5). Exclude laps 1–2 and say so in the source line.
C2. Compare these drivers ⭐⭐. 2025 Japanese GP qualifying. Redraw Figure 25.7b for Piastri against Leclerc using boxbox.laptime.delta_trace(ref, cmp, laps=laps, align="sectors"). Print the share of the trace inside ±0.05 s, the number of sign changes (|Δ| > 0.005 s), and the stretches beyond the band. Title the chart with your two headline numbers. Expected shape: one figure, three printed lines, and a title of the form "… changed hands N times; X % inside the noise band".
C3. Audit a palette ⭐⭐. Run viz.palette_report on the 2025 driver colours you would use for a five-car chart of Verstappen, Tsunoda, Lawson, Hadjar and Gasly (team colours from the 2025 Japanese GP). Which pairs collide, and why is the answer guaranteed for one of them before you run it? Propose and implement a cue for every failing pair. Expected shape: a per-colour table (hex, contrast, pass/fail) and a pair table sorted by worst-case ΔE. Red Bull's team-mates have ΔE = 0 by construction.
C4. Build the strategy ⭐⭐⭐. Use boxbox.strategy.fit_race_model and optimise for the 2026 Barcelona GP (Chapter 12's race) and draw the best plan for one, two and three stops with viz.strategy_chart, plus the strategies of the first three finishers (strategy.actual_strategies). Label each bar with its modelled cost. Expected shape: a six-row stint chart with costs at the right. For comparison, Chapter 12 found the unconstrained best was a three-stop, M-H-H-H (12, 30, 48), with the best two-stop 3.638 s slower and the best one-stop 39.858 s slower. The model is deterministic, so with the same arguments as Chapter 12's script (optimise(model, max_stops=3)) your numbers should match; if they do not, compare the arguments before blaming the chart.
C5. Predict the race ⭐⭐⭐. Use viz.outcome_hist to compare the finishing positions of drivers starting P1 in 2014–2019 with those starting P1 in 2022–2026 (Jolpica results, actual grid; DNF as its own bin with labels={21: "DNF"}). Before plotting, predict which era has the larger DNF bar. Expected shape: one figure with two step histograms, and printed win, podium and not-classified shares with n for each era. Compare your DNF shares with the book's reliability figures: 12.8 % of all starters failed to finish in 2022–25.
C6. Small multiples, done right ⭐⭐. Take the 2025 Japanese GP and draw, for the top six finishers, lap time against tyre age for every stint (MEDIUM and HARD), one panel per driver, sharing x and y. Then draw the same grid with sharey=False and write two sentences on what changes in the reader's impression. Expected shape: two 2 × 3 figures and a short comparison. Use clean, fuel-corrected laps (toolkit default, labelled as an assumption).
C7. The deuteranopia render ⭐⭐. Take any three figures you have made in this book and pass them through viz.simulate_figure(fig, "deutan"). For each one, write down one element that fails and the fix. Expected shape: a 3 × 2 grid of images (normal and simulated) and a three-row table (figure, failure, fix).
C8. An interactive stint explorer ⭐⭐⭐. Extend code/06_interactive_plotly.py to make an HTML stint chart for any race: horizontal bars by compound, with hover showing the stint's laps, tyre age at start and the driver's median clean lap on that stint. Write a CSV table view and a static fallback with viz.strategy_chart. Expected shape: an HTML under 100 KB (CDN plotly), a CSV and a PNG.
Part D — Strategy & Judgment ⭐⭐⭐
D1. Call the pit stop: 2025 Japanese GP, lap 20. You are on the McLaren pit wall. Norris is 1.4–2.0 s behind Verstappen on mediums about 20 laps old (1.380 s at the end of lap 19); Piastri is about 4 s behind Verstappen. The green-flag pit loss at Suzuka is in the book's circuit table (Chapter 12), and Chapter 13 found the undercut succeeds 78.6 % of the time when the attacker is within 1 s, falling to 19.3 % at 2–3 s. (a) Do you pit Norris on lap 20 to try the undercut, or Piastri? (b) After you decide, look at what happened and redraw Figure 25.1b to show it.
Reveal
McLaren stopped Piastri on lap 20 and Norris on lap 21, the same lap as Verstappen (stint data). With Norris 1.3–2.0 s behind, he was outside the under-1-second band in which the undercut usually works, and Verstappen covered by stopping on the same lap. After the stops, Norris's gap to Verstappen went from 1.314 s (end of lap 21) to 1.860 s (lap 22) and 2.551 s (lap 24). Piastri, who stopped first, was 4.014 s behind at the end of lap 19 and 3.766 s behind at the end of lap 22, so his early stop gained him about a quarter of a second on Verstappen and no positions. A good redesign of Figure 25.1b for this question marks the three in-laps with open circles and annotates the gap at the end of laps 19 and 23.
D2. Design the setup (of a chart). A broadcaster asks you to design a single graphic, shown on screen for 8 seconds, that tells viewers how the 2026 Las Vegas GP was won. Using only this chapter's data, choose the form, the reference, the colours and at most two annotations. Justify each choice against 25.1–25.3, and say what you are leaving out.
Guidance
A strong answer uses the gap to Verstappen (a fixed reference), draws only the cars that matter (Verstappen, Norris and Piastri, who climbed from 17th), shades the lap-19 safety car and puts the result in the title ("Verstappen controlled it; Piastri climbed from 17th to 3rd"). It leaves out the field, the lap times and the stint chart: every car stopped under the same safety car, so strategy did not separate anyone. Eight seconds is enough for one shape and one number, not three panels.
D3. The honesty audit. Pick one chart from an earlier chapter of this book that you think could mislead. Apply the Chapter Summary checklist to it, item by item, and write a one-paragraph review as if for the author. You must include at least one point in its favour.
D4. Colour policy for a team. You are the analyst for a team whose colour fails 3:1 on white (choose one from Figure 25.2). Write a one-page colour policy for your team's internal charts: which variant to use on light and dark backgrounds, how team-mates are distinguished, what happens when your colour sits next to a rival with a similar hue, and how you test it. Use viz.darken_to_contrast and viz.palette_report for the numbers.
Guidance for D4
For Mercedes (#00D7B6 in 2026, 1.84:1), a reasonable policy is: use the published colour on dark backgrounds (it passes easily there); use darken_to_contrast (#05A58B, 3.11:1) on white; never place the team's line next to Haas or Cadillac without a marker, because the darkened teal merges with them under deuteranopia (Case Study 2); always dash the second driver; and run palette_report plus a deuteranopia render on every published chart.
Part M — Mixed / Interleaved ⭐⭐–⭐⭐⭐
M1 (Ch 19 + Ch 25) ⭐⭐. Chapter 19 showed that the uniform delta puts a −0.258 s spike at the Suzuka hairpin and the sector-anchored delta −0.175 s. Draw both on one delta panel with the ±0.05 s noise band. Then state, in the chart's title, which features survive both alignments. Use Chapter 19's "robust segment" rule: the same sign and within 0.05 s.
M2 (Ch 14 + Ch 25) ⭐⭐⭐. Chapter 14 measured how often each circuit has a safety car or VSC. Choose the five circuits with the highest neutralisation share in 2023–26 and draw them as small multiples of their race traces for one season, on a shared y scale, with viz.race_trace(reference=…). Pick the reference that keeps the safety cars from dominating the picture, and justify the choice.
M3 (Ch 22 + Ch 25) ⭐⭐⭐. Chapter 22 showed that degradation depends on the fuel correction. For Verstappen's HARD stint at Suzuka 2025, draw three panels: raw lap time, toolkit-default fuel correction, and the data-driven fuel effect from metrics.estimate_fuel_effect. Use one shared y window and print each slope with its interval in the panel title. What should a published deg chart always say in its source line?
M4 (Ch 12 + Ch 13 + Ch 25) ⭐⭐⭐. For the 2026 Miami GP (Chapter 13's undercut), design a two-panel figure: the gap between Antonelli and Norris on laps 15–40 (top), and both cars' lap times (bottom) on a shared lap axis. Mark both in-laps, clip the out-lap with viz.clip_view, and check Mercedes teal's contrast. Fix it if it fails.
M5 (Ch 2 + Ch 25) ⭐⭐. Using Chapter 2's frozen-telemetry statistic (about 9.4 % of the fastest 2026 qualifying laps have a frozen stretch longer than 2 s), draw a small-multiple grid of the 2026 Shanghai qualifying top ten, with frozen stretches shaded as in Figure 25.10. How many of the ten pass the quality check?
Part E — Research & Extension ⭐⭐⭐⭐
E1. A colour-safe F1 palette. Design a set of 11 team colours for 2026 that (a) a fan would still recognise, team by team, (b) all reach 3:1 on white, and (c) have no pair below ΔE 6 under deuteranopia or protanopia. Measure the trade-off between "recognisable" (ΔE from the published colour) and "safe" (worst-pair ΔE). Case Study 2 shows that lightness alone cannot do it, so you will need hue shifts, and you must decide which teams move. Report the palette, the full pair table and an honest list of the teams whose identity suffers.
E2. A Box Box race report. Using viz and the earlier modules, write a function race_report(session) -> list[Figure] that produces a consistent four-figure report for any 2023–26 race: gap to the winner (fixed reference), focused position chart (automatically choosing the biggest movers), stint chart and pace violins. Run it on five races of your choice and critique its automatic choices. Where did it pick the wrong story?
E3. Uncertainty you can see. Build a visualisation of Chapter 27's Monte Carlo output (when it is available) that shows, for each driver, the probability of each finishing position. Compare three designs, a heatmap, small-multiple histograms and a dot plot of median plus 10–90 % range, and test each with three readers. Which design do they read most accurately, and which do they prefer? (These are often not the same.)