Contents/ Part III · Visualizing Data/ Chapter 15

Charts for Numerical Data

Four workhorse charts cover almost everything you do with continuous data: the histogram, the box plot, the line chart, and the scatter plot. Knowing which to reach for, and how each can fool you, is the heart of exploratory analysis.

⏱️ ~13 min read
🐍 Notebook included
📊 Chapter 15

Categorical charts (see Charts for Categorical Data) showed how a total splits across groups. Numerical charts answer different questions: what shape does this quantity take, how do groups compare, how does it move over time, and how do two quantities relate?

📈
Charts for numerical data reveal the distribution, comparison, trend, or relationship of one or more continuous variables. The four staples are the histogram, box plot, line chart, and scatter plot.
1

Four Charts, Four Questions

The fastest way to choose is to start from the question and the data, not the chart:

Histogram one variable's shape Box plot compare groups Line chart trend over time Scatter plot relate two variables One variable to histogram · groups to box plots · time to line · two variables to scatter
2

The Histogram: Shape of One Variable

You built histograms in the Frequency Distributions chapter and met shape in the Shape of a Distribution chapter. Here the key idea is a warning: the bin width is an editorial choice, not a fact about the data.

Too few bins

Oversmooths: real peaks and gaps vanish into a single block.

Too many bins

Noisy: every random wiggle looks like structure.

📊
Never trust a single binning

Try several widths and report what holds up. For a principled default, Freedman-Diaconis (bin width = 2·IQR / n1/3) uses the IQR, so it resists outliers and skew. A KDE (kernel density estimate) is a smoothed alternative, but its bandwidth is the same trap under a new name, and it can invent density where no data exists.

Use a density y-axis (area sums to 1) when bins are unequal-width or you overlay a KDE or compare groups of different size; otherwise a frequency count is fine.

To sidestep the binning trap altogether, plot the ECDF (empirical cumulative distribution function): sort the values and draw the running fraction at or below each x. There is nothing to tune, every point is shown exactly, and any percentile reads straight off the y-axis (the median is where the curve crosses 0.5). The companion notebook shows it on the same bimodal data, and the two modes appear as two steep climbs, no bin-width decision required.

3

The Box Plot: Compare, but Beware

A box plot packs a five-number summary into a tiny footprint: the median line, a box from Q1 to Q3 (the IQR), whiskers to the furthest point within 1.5×IQR, and dots for outliers. That compactness makes it the best tool for comparing many groups side by side.

🫥
Its blind spot: shape

A box plot cannot show modality. Two completely different distributions can produce the same box. Below, a bell, a two-humped set, and a flat one share almost identical boxes, while their histograms are nothing alike.

Same box plot, different data Normal Bimodal Uniform box plots above · histograms below
🎻
When shape matters, show it

A violin plot adds a mirrored density curve, so it reveals the two humps a box would hide. For small samples, just show the points (a strip or swarm plot). And always state your whisker convention, "box plot" has no single definition (Tukey's 1.5×IQR versus min-to-max), so a box plot is ambiguous without it.

4

Line Charts, Scatter Plots & Honesty

The line chart connects points to assert order and continuity, which makes it ideal for a value over ordered time, and wrong for unordered categories (the line implies a trend between them that does not exist).

Declutter spaghetti

Too many lines is a tangle. Highlight the one series that matters, gray the rest, and label it directly.

Mind the slope

Aspect ratio shapes perceived rates of change; avoid dual y-axes, which can fake a correlation.

The scatter plot shows the relationship between two numeric variables. Read it in four moves: direction (up or down), form (line or curve), strength (tight or loose), and outliers.

Fight overplotting

With thousands of points a blob hides the density. Use transparency, smaller markers, or a hexbin.

Association, not cause

A tight scatter shows a relationship, not that one variable causes the other. More on this in the regression chapters.

⚖️
Zero baseline: bars yes, lines no

The Charts for Categorical Data chapter insisted bar charts start at zero, because bar length encodes the value. Line and scatter charts encode value by position, so they need not start at zero; forcing zero can flatten a real trend into a useless line. The catch: this same freedom is the classic way to exaggerate a trend, so choose an honest scale and label the axis clearly.

🦖
Always plot your data: Anscombe's quartet

Four datasets can share the same mean, variance, correlation, and regression line, yet look completely different: one clean line, one curve, one dragged by a single outlier, one held up by a lone leverage point. Summary statistics alone would call them identical. Only the picture tells the truth. (The modern "Datasaurus Dozen" makes the same point with thirteen shapes, including a dinosaur.)

🤖
Why this matters for data science

These four charts are the core EDA loop: look at the distribution, compare groups, check trends, examine relationships, all before modeling. In Python that is hist, boxplot, plot, and scatter (or seaborn's histplot, boxplot, lineplot, scatterplot). Plotting first is what catches the surprises a summary statistic would quietly hide.

5

Numerical Charts in Machine Learning & AI

The histogram and box plot are the first things a data scientist draws for any numeric feature. They are how you diagnose the problems, skew, outliers, odd scales, that decide the preprocessing a model needs.

Numerical chartWhere it shows up in MLWhat it reveals
Histogram / KDEThe first look at every numeric feature and at model residualsSkew that calls for a transform, and multi-modality that hints at mixed groups
Box plotOutlier screening before training, and comparing a metric across groupsThe points past the whiskers are the candidates to clip, winsorize, or investigate
Residual plotThe core diagnostic for a regression modelA pattern in the residuals means the model is missing structure in the data
🤖
Plot the feature before you scale it

Whether a feature needs a log transform, a robust scaler, or outlier clipping is a question a single histogram or box plot answers in seconds. Skipping that plot and scaling blind is how a heavy tail quietly sabotages a model, the picture is the cheapest diagnostic you have.

6

Real-World Example: Flight Arrival Delays

Flight delays are a numeric variable with real character: most flights are close to on-time, but a long right tail of serious delays drags the average up. On these 500 flights the mean delay is about 14 minutes but the median is only 8, and a box plot flags dozens of long-delay outliers past the upper whisker. The companion notebook draws the histogram and box plot side by side.

📂 Dataset · charts-for-numerical-data--flight_delays.xlsx

One row per flight: flight_id, airline (three carriers), and delay_minutes (negative means an early arrival). The delay column is right-skewed with a heavy upper tail, exactly the shape a histogram and a box plot are built to reveal.

🐍

Bring it to life in Python

The companion notebook shows the histogram bin trap across several widths, reveals what a box plot hides versus the real histograms, declutters a spaghetti line chart, reads a scatter and tames overplotting with a hexbin, and recreates Anscombe's quartet with its identical regression line.

📓 View Notebook (code & outputs) ▶ Open in Colab ⬇ View / Download on GitHub

View opens the rendered notebook instantly (no setup). Open in Colab runs & edits it live in your browser. To run locally, install numpy, pandas, scipy, matplotlib and launch jupyter notebook.

🎓 Key Takeaways

  • Match chart to question: one variable to histogram, groups to box plots, time to line, two variables to scatter.
  • Histogram bin width is editorial; try several and lean on Freedman-Diaconis.
  • Box plots compare groups but hide modality; a violin or strip plot shows the shape they conceal.
  • Lines and scatter encode by position, so they need not start at zero (unlike bars), but keep the scale honest.
  • Anscombe's quartet: identical summary stats, four different shapes. Always plot your data.
7

Practice Challenges

Five short challenges, beginner to intermediate. Try them on paper or in Python before checking the solutions.

1

The bin trap

Plot rng.normal(0,1,2000) as a histogram with 3 bins and again with 80 bins. Describe how the apparent shape changes, and compute the Freedman-Diaconis bin count.

Hint: bin width = 2·IQR / n^(1/3).
2

What the box hides

Build a clearly bimodal dataset. Show it as a box plot and a histogram side by side. What does the box plot fail to reveal?

Hint: concatenate two normals with different means.
3

Pick the chart

Name the best chart for each: (a) one exam's score distribution; (b) salaries across five departments; (c) monthly revenue over three years; (d) advertising spend vs. sales.

Hint: distribution, groups, time, relationship.
4

Axis honesty

A revenue series barely moves over a year. Show it on a truncated y-axis and a full one. Does a line chart have to start at zero? Explain.

Hint: lines encode value by position, not length.
5

Always plot

Take two of Anscombe's datasets, confirm they share the same mean, correlation, and regression line, then plot both. What is the moral?

Hint: identical stats can hide a curve. Use np.polyfit and np.corrcoef.
Check your work

A fully-worked solutions notebook walks through all five challenges in the same visual style. Try them yourself first, then compare.

📓 View Solutions ▶ Open Solutions in Colab ⬇ View / Download on GitHub
8

Quiz: Test Yourself

Eight quick questions on numerical charts. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.