Review
Reconstruct the path from a numerical question to a checked line, bar, scatter plot, histogram, or heatmap, then use the same evidence to debug a wrong result.
Begin with the Question
A plot is useful when it preserves the structure needed to answer a numerical question. Do not begin with a chart name. Begin by asking what the positions in the data mean and which relationship the reader needs to see.
| Question | Structure to preserve | Smallest useful plot |
|---|---|---|
| How does a reading change in order? | ordered positions | line plot |
| Which named category is larger? | category names and magnitudes | bar plot |
| How do two measurements vary together? | row-by-row pairs | scatter plot |
| Where do values concentrate? | counts within intervals | histogram |
| How do values vary across two axes? | table rows, columns, and cell values | heatmap |
A plot also discards information. A histogram discards observation order. A line joins neighboring positions even though only the marked points may have been measured. A heatmap replaces exact printed values with colors. Keep the underlying numbers close enough to check an important mark, bin, pair, or cell.
Construct Each View Deliberately
Use the explicit Matplotlib figure and axes objects:
The horizontal coordinate must carry a real order before a line is justified. For named categories, bars preserve separate magnitudes without implying a continuous path. Their usual zero baseline matters because bar length encodes the value.
A scatter plot preserves pairs only when matching positions still describe the same observation. Sorting one array without applying the same order to the other silently breaks that relationship. An equality line is useful only when equal horizontal and vertical values have a meaningful interpretation.
A histogram requires explicit thought about bin edges. A value belongs to an interval, and the bar height records how many values fall there. Use the same edges when comparing datasets. With a small sample, describe only the visible counts; do not claim that the plot reveals a stable population shape.
For a two-dimensional table, imshow maps array row zero to the first displayed
row and array column zero to the first displayed column. Label both axes and
check one known cell. Use a sequential color scale for values that move from a
low amount to a high amount. Use a diverging scale with meaningful shared
limits when values extend on both sides of a reference such as zero.
Read Evidence before Explaining It
Separate an observation from an explanation.
- Observation: “Sensor B is above sensor A at all three observations.”
- Possible explanation: “The sensors may use different scales.”
The first statement can be checked from the values and plot. The second needs more evidence. A plot can show a pattern, difference, or unusual value. It does not by itself establish why that pattern exists.
Before accepting a view, check the axes, units, scale, limits, and colorbar. Then inspect the source numbers. A polished figure with a truncated bar axis, broken row pairs, inconsistent histogram bins, or different heatmap color limits can make a false comparison look persuasive.
Make Comparisons Fair and Reusable
Comparable panels need comparable rules. Reuse limits, bin edges, or color limits when the question asks the reader to compare magnitudes. Distinguish series with markers, line styles, or direct labels as well as color when possible. A legend should explain a real distinction, not repeat information already clear from the axes or title.
Keep ownership explicit:
Saving the figure preserves the visible result, but reproducibility also needs the source data and the code or settings that produced it. Close the figure you own so that a later run does not accidentally display an earlier open figure.
Use a Plot as One Debugging Tool
When a calculation runs but looks wrong, use a short method:
- state the expected numerical behavior;
- compute a small trusted reference;
- compare the reference with the program result;
- describe the first visible disagreement;
- propose one testable cause;
- reduce the input and find the first wrong value;
- repair the calculation; and
- verify it numerically and visually.
The plot helps locate a disagreement. The numerical check decides whether the repair satisfies the stated requirement. Keep both forms of evidence. A visual match can hide a small error, while a list of correct-looking numbers can hide an incorrect trend or isolated outlier.
Explain the Complete Path
You should now be able to move from a question to evidence:
question
→ structure that must remain visible
→ smallest suitable plot
→ one checked mark, pair, bin, or cell
→ cautious observation
→ numerical verification
The goal is not to collect every Matplotlib function. It is to make a numerical result easier to inspect, explain, compare, save, and debug.