Choosing a Plot
Choose a plot from the numerical question and the structure needed to answer it. Line plots preserve order, scatter plots preserve pairs, histograms preserve value counts, and array or surface displays preserve spatial coordinates.
A numerical array contains values and structure. Before choosing a plot, decide which part of that structure matters:
- the order of the values;
- the pairing between two quantities;
- the distribution of one quantity;
- the rows and columns of a two-dimensional array;
- the output of a function across two input axes.
Different plots preserve different structure. A line plot preserves order. A scatter plot preserves pairs without connecting them. A histogram keeps value counts but discards order. The first question is therefore not “Which Matplotlib function should I call?” It is “What do I need to inspect?”
Begin with a numerical question
Suppose a training program records one loss value after each epoch:
The question “Does loss decrease as training proceeds?” depends on epoch order. A line plot keeps that order and connects consecutive observations.
Now suppose a model produces one prediction for each target:
The question “Are predictions close to their targets?” depends on paired values, not on which example happened to be stored first. A scatter plot keeps each target–prediction pair without suggesting a sequence.
The data alone does not determine the plot. The question and the meaning of the axes determine it.
Preserve the structure you need
This table provides a starting point:
| Question | Structure to preserve | Useful first plot |
|---|---|---|
| How does a value change over time, epoch, or ordered input? | order | line plot |
| How are two measurements related? | pairs | scatter plot |
| Where are values concentrated? | counts within value intervals | histogram |
| Where are large and small values in a matrix? | rows, columns, and values | heatmap |
| Where is a function of two inputs high or low? | two input coordinates and one output | contour or surface plot |
These are not automatic rules. A one-dimensional array can be shown as a line plot or a histogram, but the two plots answer different questions. The line plot keeps the array's order. The histogram discards that order and summarizes how often values occur within intervals.
Compare three views of related data
Run this example and inspect the meaning of each panel. You can edit the measurements or change the number of histogram bins.
Compare order, pairs, and distribution
The three plots use related arrays but preserve different information. Change one value and observe which panels reveal the change most clearly.
Ready to run.
The first panel shows when the training loss changes. The second treats each training and validation loss as one pair. The third shows how validation-loss values are distributed, but it no longer shows which epoch produced each value.
Inspect numbers and plots together
A plot summarizes numerical values through position, length, color, or area. That summary can reveal patterns quickly, but it can also hide exact values. Keep small numerical checks beside the figure:
These checks answer questions that the plot may not answer precisely. They can also expose a wrong shape, an unexpected range, or a missing value before you interpret the image.
The reverse is also true: a printed mean can look reasonable while a plot reveals two clusters or one unusual point. Numerical summaries and plots support each other.
Check the axes before the pattern
Before interpreting a plot, identify:
- what quantity each axis contains;
- what one point, line, bar, or cell represents;
- whether order and pairing have been preserved;
- whether the axes are linear or logarithmic;
- whether limits or color scales hide part of the data.
A curve can appear steep because the vertical range is narrow. Two heatmaps can use the same color for different values if they have different color limits. A scatter plot can lose its relationship if one array was shuffled without the other. Read the plot's construction as carefully as its visible pattern.
Separate observation from explanation
Begin with a statement that another reader can verify from the figure:
The validation loss decreases through epoch 4, then increases at epoch 5.
This is an observation. It describes visible evidence.
Then propose an explanation:
The increase may indicate that the model has started to fit the training data
more closely without improving on validation data.
This is an interpretation, not a fact established by the plot. It suggests what to investigate next. Keeping these two statements separate prevents a plausible story from being mistaken for evidence.
Plot small results early
A small plot can check a computation before it becomes part of a larger experiment. For example, plot six points from a formula before evaluating it at a million positions. If the small curve has the wrong direction or shape, inspect the formula while every value is still easy to calculate by hand.
Plotting early does not replace tests or shape checks. It adds another form of evidence:
question -> small computation -> numerical checks -> plot -> observation
Use that sequence throughout the chapter.
You have one accuracy value for each training epoch and want to see when the accuracy changes. Which plot is the best first choice?
Select one choice, then check.
HintPreserve epoch order
The horizontal position should show the ordered training step.
SolutionUse a line plot
A line plot preserves epoch order and shows how accuracy changes from one recorded epoch to the next.
You have one prediction and one target for each example. You want to see whether predictions lie near their targets without implying that the examples form a sequence. Which plot should you use first?
Answer it first, then check.
HintKeep pairs, not sequence
Each example should contribute one point with a target coordinate and a prediction coordinate.
SolutionUse a scatter plot
A scatter plot preserves paired values without connecting examples in their storage order.
Which statement is a direct observation?
Select one choice, then check.
HintReport visible evidence
Avoid statements that use the plot to assert an untested cause or future result.
SolutionDescribe the final point
“The final validation-loss point is higher than the previous two points” can be checked directly from the plot. Overfitting is a possible interpretation that needs more evidence.
Why should a program print shapes, ranges, or summary values as well as drawing a plot?
Select one choice, then check.
HintCombine two forms of evidence
A plot can reveal shape quickly, while a printed check can retain exact size, range, or value.
SolutionUse numerical and visual evidence together
Printed shapes and summaries preserve exact evidence. The plot makes broader structure visible. Neither form makes the other unnecessary.
The array [0.6, 1.2, 0.7, 1.0, 0.9] stores one validation loss per epoch. If
you show only a histogram, which information is no longer visible?
Select one choice, then check.
HintCompare sequence with distribution
A histogram counts values within intervals rather than placing them at epoch positions.
SolutionEpoch order is removed
The histogram can show the distribution's range and concentration, but it cannot show which epoch produced each loss.
Retain the question–structure–plot method
For each new figure:
- write the numerical question;
- name the structure that the answer depends on;
- choose a plot that preserves that structure;
- keep useful numerical checks;
- state the visible observation before proposing an explanation.
The following lessons apply this method to each plot type in more detail.