Display a Numerical Table

Map a table's rows, columns, and values to a labeled grid, then check its orientation and the numerical meaning of its colors.

A histogram groups one sequence of values and discards their positions. A two-dimensional measurement table asks a different question: where does each value sit across observation rows and sensor columns? imshow preserves that grid and represents each value with color.

We will display the centered table from Chapter 11, Computing with Arrays:

Its shape is (3, 2). Rows are observations; columns are sensors. The first row contains readings below their sensor means, the middle row equals the means, and the last row lies above them.

Map Array Positions to Cells

imshow maps the two array indexes directly to a rectangular grid. With the usual upper origin, array row 0 is the top row, and column 0 is the left column:

Display the centered measurement table

Each cell preserves one observation–sensor position. Change a value and compare the printed table, cell position, and colorbar.

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

The top-right cell represents centered[0, 1], which is -2.0. The bottom-right cell represents centered[2, 1], which is 2.0. Reading those two known positions before interpreting the colors checks the orientation.

The tick labels are not decoration. They state what each index means. Without them, a viewer might guess that rows are sensors or that the first observation starts at the bottom.

Q1. Locate a heatmap cell

With origin="upper", which value appears in the bottom-left cell?

Compute it first, then check your number.

HintTranslate the visible position to indexes

The bottom row is observation 2, and the left column is sensor 0.

SolutionRead row 2, column 0

centered[2, 0] is 1.0.

Not attempted
Review

Not marked done.

Use Color around a Meaningful Center

These values describe signed differences from a mean. Zero has a special meaning: the reading equals its sensor mean. Negative and positive values lie on opposite sides of that reference, so a diverging color map is suitable.

The explicit limits

place zero at the center and give equal-magnitude negative and positive values equal visual strength on opposite sides. A value of -2 and a value of 2 therefore reach opposite ends of the same scale.

A table of nonnegative counts has no meaningful negative side. It usually needs a sequential color map whose intensity increases in one direction. Choose the scale from the meaning of the values, not because one palette looks attractive.

Q2. Choose the color scale from meaning

Which display choice best fits the centered table?

Choose one

Select one choice, then check.

HintAsk what zero means

Zero means equal to the sensor mean; negative and positive differences should appear on opposite sides of that reference.

SolutionCenter the color meaning on zero

Use a diverging map with limits -2 and 2. Equal magnitudes then receive comparable emphasis on opposite sides of zero.

Not attempted
Review

Not marked done.

Read Numerical Meaning from the Colorbar

The colorbar maps displayed colors back to numerical values. Its label gives the quantity and unit. Without it, a strong color says only that two cells look different; it does not say whether a cell represents 0.2, 2, or 20.

Fixed limits are also needed when comparing two heatmaps. If each panel chooses limits from its own minimum and maximum, the same color may represent different values. Shared vmin, vmax, and color map give the panels one numerical color language.

Before interpreting a heatmap, inspect:

  1. the numerical array and its shape;
  2. the meaning of rows and columns;
  3. one known cell and its visible position;
  4. the colorbar label and limits.

This order catches a transpose or reversed-origin error before color patterns become a story about the data.

Q3. Build and verify the table display

Complete the display with a symmetric diverging scale, a labeled colorbar, and an orientation check for the top-right cell.

Editable Python

Command/Ctrl + Enter. Python runs in your browser.

Ready to run.

HintState color and orientation explicitly

Pass cmap="coolwarm", vmin=-2.0, vmax=2.0, and origin="upper" to imshow. Add figure.colorbar(image, ax=ax, label="centered reading (°C)"), then check centered[0, 1] == -2.0.

SolutionTie color and position to numbers

The known cell confirms the array-side orientation contract, while the labels and explicit origin state how that contract is displayed.

Not attempted
Review

Not marked done.

imshow preserves row and column positions while color represents value. Name both axes, check a known cell, use a scale that matches the value's meaning, and label the colorbar. The next lesson chooses among line, bar, scatter, histogram, and heatmap views from the question each must answer.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 3 exercises marked done

Review

Not marked done.