Review

Core idea

Plots are inspection tools.

Use them to notice patterns, mistakes, outliers, distributions, and computed curves.

Line plots

Use line plots when order matters:

plt.plot(x, y, marker="o")

x and y should have the same length.

Scatter plots

Use scatter plots for paired measurements:

plt.scatter(x, y)

Prediction-versus-target plots are a common ML inspection tool.

Histograms

Use histograms for distributions:

plt.hist(values, bins=5)

Histograms ignore order and show counts by value range.

Plotting arrays

Use imshow for a two-dimensional array:

State what rows and columns mean.

Labels and saving

Useful labels:

Save a figure with:

plt.savefig("loss.png", dpi=150, bbox_inches="tight")

In a local script, plt.show() displays the figure. Save before showing or closing it when you also need a file.

When comparing separate imshow figures, use common vmin and vmax limits so equal colors represent equal values.

Visual debugging

After making a plot, write the observation:

The computed curve is linear, but the expected curve bends upward.

This turns a picture into evidence.