How do you make figures reproducible and generate them automatically in a report or CI pipeline?

Quick Overview

Asks how to make Matplotlib figures reproducible and build them automatically for a report or a CI pipeline. Tests headless rendering, seeding, pinning data, fonts and library versions, deterministic file output and visual regression tests.

How do you make figures reproducible and generate them automatically in a report or CI pipeline?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

How do you make figures reproducible and generate them automatically in a report or CI pipeline? Assume the figures are made with Matplotlib (or Seaborn on top of it) and feed a report that is rebuilt whenever the code or data changes. ```hint List the hidden inputs Besides your plotting code, list everything that can change a rendered image: the environment, the data, random draws, and anything the library reads from the machine it runs on. ``` ```hint Think about detection Ask how a CI job would tell you that a figure changed when it should not have, and how strict that check can be. ``` ### What a Strong Answer Covers - Rendering without a display and building every figure from a script - Removing sources of drift: random seeds, data snapshots, library and font versions, style settings - What it takes for output files to be identical across runs, and when a tolerance-based comparison is the better test - How figure generation plugs into report builds and CI: the build step, artifacts, failing on unexpected changes ### Follow-up Questions - Two machines running the same code produce PNGs that differ by a few pixels. Where would you look? - How would you write a test that fails when a chart changes unexpectedly but tolerates harmless rendering differences? - How would you avoid regenerating every figure in a large report when only one input changed? - How do you keep a notebook-based report reproducible?

Overview: Asks how to make Matplotlib figures reproducible and build them automatically for a report or a CI pipeline. Tests headless rendering, seeding, pinning data, fonts and library versions, deterministic file output and visual regression tests.

PracHub logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you make figures reproducible and generate them automatically in a report or CI pipeline?

Assume the figures are made with Matplotlib (or Seaborn on top of it) and feed a report that is rebuilt whenever the code or data changes.

What a Strong Answer Covers Guidance

  • Rendering without a display and building every figure from a script
  • Removing sources of drift: random seeds, data snapshots, library and font versions, style settings
  • What it takes for output files to be identical across runs, and when a tolerance-based comparison is the better test
  • How figure generation plugs into report builds and CI: the build step, artifacts, failing on unexpected changes

Follow-up Questions Guidance

  • Two machines running the same code produce PNGs that differ by a few pixels. Where would you look?
  • How would you write a test that fails when a chart changes unexpectedly but tolerates harmless rendering differences?
  • How would you avoid regenerating every figure in a large report when only one input changed?
  • How do you keep a notebook-based report reproducible?