Line Plots

A line plot shows how one quantity changes with another.

Use it when order matters:

  • time steps;
  • training epochs;
  • input values along a curve;
  • a sequence of measurements.
plt.plot(x, y)

x and y should have the same length.

Plot a computed curve

Plot a quadratic curve

Runs locally with Python in your browser.

Ready to run.

The markers show the actual points. The line connects them so the trend is easier to follow.

Check matching lengths

This should be automatic:

If x has six values and y has five values, the plot is not well-defined. The points cannot be paired.

Use labels early

Labels are not cosmetic. They record meaning.

A plot without labels is easy to misread later.

Exercise: Same length

If x.shape is (6,), what should y.shape be for a simple line plot?

Answer it first, then check.

Hint

Each of the six x values needs one corresponding y value.

Solution

y.shape should be (6,). A simple line plot pairs each of the six x positions with one y value.