Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.4 — Showing Less to Show More
Data Visualization · Example 1 of 2

All points, a sample, and counts

The same 200,000 made-up points three ways. 816 of them lie outside the 200 by 150 picture, so the squares count 199,184: the first line says it.

Past a point, drawing every record makes a worse chart: dots pile on dots and the page slows down. Sampling, counting in bins and zooming into detail show more truth with less drawing. The rule is never to drop data silently.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 4 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write binIndex(x, y, size, columns) that returns one number for the square holding the point, and -1 for a point outside a grid columns squares wide.

02

Change the second example so the lonely trip is drawn as a red dot when it is in view, even while the rest are squares.

Explain it without notes

01

Why can a chart of 200,000 dots be worse than a chart of 2,000?

02

How does binning keep every record counted, while sampling does not?

All points, a sample, and counts

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

points: 200,000 | inside the picture: 199,184 | outside: 816
sample: 2,000 points, 1% of the data
squares with at least one point: 300 of 300 | most points in one square: 7,162
sample of an empty list: 0 | sample larger than the data: 2