Data Analysis with Python (pandas, polars, DuckDB) Module 10
Visualising data with matplotlib interview questions
Interview questions on visualising data with matplotlib: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
Why should a bar chart's value axis start at zero, when a line chart's axis need not?
Answered in the lesson Choosing the right chart for the question
-
Fresher
What is the difference between a Figure and an Axes in matplotlib, and why do many analysts start every chart with fig, ax = plt.subplots()?
-
Fresher
When would you show a distribution as a box plot rather than a histogram, and what can a box plot hide?
Answered in the lesson Distributions, relationships and correlation charts
-
Fresher
Why do many chart guides prefer labelling lines directly to using a legend, and when is a legend still the better choice?
Answered in the lesson Charts that communicate: annotation, accessibility
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
Leadership wants a pie chart of the company's 14 cost categories for the annual summary. What do you propose instead, and how do you deal with the smallest categories without hiding anything?
- What it tests
- Choosing a part-to-whole chart from the question behind it, keeping every part of the whole, and writing a title that carries the finding.
- First step
- Ask which decision the summary supports: which costs are largest, how the mix changed since last year, or whether one category is out of line. Each answer points to a different chart, and none of them is a pie with 14 slices, where a 1 % category is a sliver of 3.6 degrees.
- Follow-ups
-
- They insist on a pie. What is the least bad version?
- How do you show the change from last year in the same chart?
- Three categories are under 1 % each. Where do they go?
From the lesson Choosing the right chart for the question
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A product manager wants one chart of daily active users and daily revenue over six months, on two y-axes, to show that revenue follows usage. What do you build instead, and what do you say about the claim?
- What it tests
- Why two y-axes mislead, how to compare two series on one honest scale, and the gap between moving together and one causing the other.
- First step
- Put both series on a common footing before drawing anything: divide each by its average in the first week and multiply by 100, so each first-week average is 100 on one axis; individual daily points can differ. Then ask which ratio would stay flat if the claim were true, and plot that as well.
- Follow-ups
-
- The two indexed lines move together. Does usage drive revenue?
- Usage is counted daily and revenue only weekly. What changes?
- Leadership also wants to see the actual numbers. How?
From the lesson Choosing the right chart for the question
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
The value labels on a revenue bar chart read 4.41e+06, 3.72e+06 and so on, and the y-axis runs from 0.5 to 2.0 with a small 1e6 above it. Explain both effects and fix the chart so that nobody has to count zeros.
- What it tests
- Knowing matplotlib's default formats for value labels and ticks, choosing one unit for the reader, and keeping the axis and the labels consistent.
- First step
- Treat them as two separate defaults, one for the value labels and one for the axis, and look up what each one does with large numbers before changing anything. Then choose one unit for the whole chart, such as millions with two decimals, so that the labels and the ticks end up saying the same thing.
- Follow-ups
-
- The chart goes into a finance pack that needs exact amounts. What changes?
- Half the categories are below 100,000. Does one unit still work?
- How do you test that a chart's labels use the agreed unit?
From the lesson Plotting with matplotlib and pandas
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A nightly job saves 40 charts as SVG files into a Git repository. Every night all 40 files show up as changed, even on nights when the data did not change. What is going on, and how do you make unchanged charts produce unchanged files?
- What it tests
- What makes matplotlib's SVG output differ between runs, the settings and conventions that make it reproducible, and how to keep it that way across machines.
- First step
- Diff two of the files instead of guessing. If the data and the drawing did not change, the lines that differ are not data: find which parts of the SVG text change between two saves of the same chart, then look for the settings that control them.
- Follow-ups
-
- After the fix, the files still change when a colleague runs the job on another laptop. Why?
- Would saving PNG files instead avoid the problem?
- How do you prove in CI that the fix holds?
From the lesson Plotting with matplotlib and pandas
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A script draws one chart per store for 3,000 stores. It gets slower and slower and is killed for using too much memory after a few hundred charts. What is happening, and how do you restructure it?
- What it tests
- How pyplot keeps figures alive, closing figures or avoiding pyplot, reusing one figure, and measuring memory instead of guessing.
- First step
- Count the open figures while it runs: plt.get_fignums() grows by one per store, because pyplot keeps every figure it created until it is closed. Then check the job's log for warnings from matplotlib, and measure the process's memory every hundred stores instead of guessing.
- Follow-ups
-
- Closing each figure fixed the memory, but 3,000 charts still take 40 minutes. What next?
- The charts are drawn inside a web request. What changes?
- How would you confirm that the leak is fixed?
From the lesson Plotting with matplotlib and pandas
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Two analysts plot the same 400 delivery times. One histogram shows one peak, the other shows two. Who is right, and how do you decide what to show the operations team?
- What it tests
- Knowing that the bin width shapes a histogram, checking a shape before trusting it, and choosing a chart that does not depend on a single bin choice.
- First step
- Do not pick a winner from the two pictures. Redraw the same data at several bin widths and draw an ECDF, which has no bins at all. Check whether the proposed groups remain plausible across these choices and in the unbinned values; neither a chosen width nor two steep ECDF stretches proves two population modes.
- Follow-ups
-
- The second peak is real. What could cause it, and what do you report?
- The team wants one standard chart every week. Which one, with which settings?
- Only 25 deliveries happened this week. Does a histogram still make sense?
From the lesson Distributions, relationships and correlation charts
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A correlation heatmap of 30 product metrics shows r = 0.02 between discount depth and units sold, and a manager concludes that discounts do not affect sales. What do you check before agreeing, and what do you show instead?
- What it tests
- What Pearson's r measures, the shapes and subgroups it misses, and why a correlation, high or low, is not evidence about cause.
- First step
- Draw the scatter plot behind the number before discussing it. A near-zero sample r reports little linear association in that sample; it does not rule out a population relationship. Check curves, cancelling subgroups, extreme products, restricted ranges and sample uncertainty.
- Follow-ups
-
- The scatter plot shows a U shape. What does that mean for the business?
- Discounts are only given to products that sell badly. How does that change the analysis?
- How would you design a test that answers the manager's question?
From the lesson Distributions, relationships and correlation charts
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A scatter plot of 2 million orders, order value against delivery time, is one solid blob. How do you show the relationship, and how do you check whether a trend line through it means anything?
- What it tests
- Remedies for overplotting, summarising a relationship with binned statistics, and judging a trend line by its residuals and its range.
- First step
- Stop drawing every point. Count the points per cell with hexbin or a 2D histogram, or plot a random sample of a few thousand, and add the median delivery time for each band of order value, which shows the trend without any fitted line.
- Follow-ups
-
- The binned medians rise and then fall. Should you fit a straight line anyway?
- How do you show the 1 % of very late orders that the blob hides?
- Drawing 2 million points makes the notebook slow. What do you change?
From the lesson Distributions, relationships and correlation charts
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A dashboard marks each region red when it misses its target and green when it meets it. A colleague with a red-green colour-vision deficiency says the two states look the same. What do you change, and how do you check that the fix works?
- What it tests
- Not relying on colour alone, adding a second cue, choosing colours that stay distinct for colour-blind readers, and checking a design with a simulator and contrast ratios.
- First step
- Treat it as a design fault, not a matter of taste: WCAG 2.2 requires that colour is not the only visual means of conveying information. Add a cue that needs no colour at all, such as the words "below target", an icon or a shape, before choosing better colours.
- Follow-ups
-
- Which two colours would you use instead of red and green, and why?
- The dashboard has 20 tiles on one screen. How do you keep it calm?
- How do you check the new design without asking your colleague each time?
From the lesson Charts that communicate: annotation, accessibility
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
You publish a line chart of monthly complaints in a public report. Write the alt text and the long description you would give it, and explain what a screen-reader user needs beyond the chart's title.
- What it tests
- Writing text alternatives that carry the finding and the numbers, splitting a short alt text from a long description, and avoiding filler.
- First step
- Start from the finding the chart was drawn to show, not from how it looks. The alt text names the kind of chart, what it measures and the finding with its key number, in about a sentence; everything else a sighted reader could read off the chart goes into the long description.
- Follow-ups
-
- The chart has 12 lines, one per region. What changes?
- Where does the long description go on a web page, and in a PDF?
- The report is regenerated every month. How do you keep the alt texts right?
From the lesson Charts that communicate: annotation, accessibility
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Stakeholders want all 12 regions on one line chart so that they can compare them. What do you build, and how do you keep the comparison honest?
- What it tests
- Replacing a tangle of lines with small multiples or highlighting, choosing shared scales or an index on purpose, and ordering and labelling for the question asked.
- First step
- Ask which comparison they need: which region is largest, which grew fastest, or how one region compares with the rest. Twelve tangled lines answer none of these well, and each question has a better chart, usually small multiples on one shared axis.
- Follow-ups
-
- Two regions are ten times larger than the rest. Does a shared axis still work?
- They insist on a single chart. What is the least bad version?
- In what order do you put the panels?
From the lesson Charts that communicate: annotation, accessibility
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All Data Analysis with Python (pandas, polars, DuckDB) interview questions · The Data Analysis with Python (pandas, polars, DuckDB) track