Exercises
Practice choosing, constructing, checking, interpreting, saving, and debugging small plots while keeping the underlying numbers visible.
These exercises combine plot choice, construction, interpretation, fair comparison, saving, and visual debugging. Check the numbers beside the figure instead of judging the image alone.
Q1. Choose a view for ordered readings
You recorded one temperature every hour. Which plot best preserves the order and spacing of the measurements?
Select one choice, then check.
HintIdentify the relationship
SolutionKeep time on the horizontal axis
Q2. Calculate one bar height
The valid reading counts for sensors A and B are 3 and 2. What height
should the bar for sensor B have?
Compute it first, then check your number.
HintKeep each name with its value
SolutionUse the category magnitude
2 and normally begins at zero.Q3. Preserve measurement pairs
Why is it wrong to sort sensor_a without applying the same order to
sensor_b before drawing a scatter plot?
Select one choice, then check.
HintTrace one point
i is formed from sensor_a[i] and sensor_b[i].SolutionKeep row identity
Q4. Count a histogram bin
Using edges [0, 2, 4, 6], how many values in [0.5, 1.5, 2.0, 3.5, 5.0]
fall in the first interval from 0 up to, but not including, 2?
Compute it first, then check your number.
HintCheck each value against both edges
2.0 begins the next interval.SolutionCount the first interval
0.5 and 1.5 satisfy , so the count is 2.Q5. Display a centered table fairly
Complete the heatmap so zero is the midpoint and values -2 and 2 use
equal color limits.
Editable Python
Ready to run.
HintMake zero the reference
cmap="coolwarm", vmin=-2, vmax=2 to imshow.SolutionUse symmetric diverging limits
image = ax.imshow(centered, cmap="coolwarm", vmin=-2, vmax=2) maps equal positive and negative magnitudes consistently.Q6. Separate evidence from explanation
Which sentence is an observation supported directly by a line plot?
Select one choice, then check.
HintDescribe before explaining
SolutionState the visible comparison
Q7. Find a misleading bar axis
A bar plot compares values 98 and 100, but its vertical axis begins at
97. What is the main risk?
Select one choice, then check.
HintRemember what bar length encodes
SolutionKeep magnitude comparison honest
Q8. Use shared histogram edges
Two groups must be compared by histogram. Which construction permits a fair bin-by-bin comparison?
Select one choice, then check.
HintMatch interval boundaries
SolutionReuse explicit bins
bins = np.array([-2, -1, 0, 1, 2]), and use bins=bins for both datasets.Q9. Save and close the intended figure
Complete the final two operations for a figure named fig.
Editable Python
Ready to run.
HintKeep figure ownership explicit
fig.savefig(path, ...), then plt.close(fig).SolutionSave and release one figure
fig.savefig(path, dpi=150, bbox_inches="tight") followed by plt.close(fig).Q10. Check a heatmap orientation
For table[2, 1] == 18, which displayed position should carry the value 18
when imshow(table) is used without transposing it?
Select one choice, then check.
HintRead both indices in order
table[row, column].SolutionMap array axes directly
Q11. Locate a wrong computed point
The reference is [2, 3, 4] and the computed result is [2, 7, 4]. What is
the index of the first disagreement?
Compute it first, then check your number.
HintCompare in order
SolutionFind the first divergence
1. That small location should be tested before changing the complete program.Q12. Verify a visual repair numerically
Complete the check after repairing one wrong transformed value.
Editable Python
Ready to run.
HintCheck the complete result
verified from np.allclose(computed, reference).SolutionKeep numerical evidence beside the plot
verified = np.allclose(computed, reference) returns True only when all repaired values agree within tolerance.You can now choose the smallest plot that preserves the needed relationship, check its construction against the numbers, describe its evidence carefully, and use it with numerical tests to find a wrong result. Chapter 13 adds controlled random variation to these deterministic computations.