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?

Choose one

Select one choice, then check.

HintIdentify the relationship
The question asks how one value changes across ordered time.
SolutionKeep time on the horizontal axis
Use a line plot with hour on the horizontal axis and temperature on the vertical axis. Markers distinguish recorded values from connecting segments.
Not attempted
Review

Not marked done.

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
Sensor B is paired with the second count.
SolutionUse the category magnitude
The bar for sensor B has height 2 and normally begins at zero.
Not attempted
Review

Not marked done.

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?

Choose one

Select one choice, then check.

HintTrace one point
Point i is formed from sensor_a[i] and sensor_b[i].
SolutionKeep row identity
Sorting only one array changes which two values form a point, so the plot no longer represents the observed pairs.
Not attempted
Review

Not marked done.

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
The value 2.0 begins the next interval.
SolutionCount the first interval
Only 0.5 and 1.5 satisfy 0x<20 \le x < 2, so the count is 2.
Not attempted
Review

Not marked done.

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

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

Ready to run.

HintMake zero the reference
Pass 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.
Not attempted
Review

Not marked done.

Q6. Separate evidence from explanation

Which sentence is an observation supported directly by a line plot?

Choose one

Select one choice, then check.

HintDescribe before explaining
Use only positions visible in the plot.
SolutionState the visible comparison
The plot supports that the final point is below the preceding point. Battery failure and future behavior require more evidence.
Not attempted
Review

Not marked done.

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?

Choose one

Select one choice, then check.

HintRemember what bar length encodes
Bars are usually judged from their baseline.
SolutionKeep magnitude comparison honest
Starting near 97 makes 98 and 100 look far more different than their values are. A zero baseline is the usual honest choice for magnitude bars.
Not attempted
Review

Not marked done.

Q8. Use shared histogram edges

Two groups must be compared by histogram. Which construction permits a fair bin-by-bin comparison?

Choose one

Select one choice, then check.

HintMatch interval boundaries
A bar can be compared only with a bar covering the same numerical range.
SolutionReuse explicit bins
Define one edge array, such as bins = np.array([-2, -1, 0, 1, 2]), and use bins=bins for both datasets.
Not attempted
Review

Not marked done.

Q9. Save and close the intended figure

Complete the final two operations for a figure named fig.

Editable Python

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

Ready to run.

HintKeep figure ownership explicit
Call fig.savefig(path, ...), then plt.close(fig).
SolutionSave and release one figure
Use fig.savefig(path, dpi=150, bbox_inches="tight") followed by plt.close(fig).
Not attempted
Review

Not marked done.

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?

Choose one

Select one choice, then check.

HintRead both indices in order
NumPy indexing is table[row, column].
SolutionMap array axes directly
The value appears at displayed row 2, column 1. Checking this known cell helps detect an accidental transpose.
Not attempted
Review

Not marked done.

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
Index zero agrees. Inspect the next pair.
SolutionFind the first divergence
The first mismatch is at index 1. That small location should be tested before changing the complete program.
Not attempted
Review

Not marked done.

Q12. Verify a visual repair numerically

Complete the check after repairing one wrong transformed value.

Editable Python

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

Ready to run.

HintCheck the complete result
Set 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.
Not attempted
Review

Not marked done.

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.

Pause and reflect

Which exercises were difficult, what mistake pattern did you notice, and what should you practice again? The note stays with this exercise set.

0 of 12 exercises marked done

Review

Not marked done.