Skip to main content
Albero Academy

Your First Plot

Build a complete, labelled line chart from data end to end.

Foundations8 min

Let's put it together: a complete, labelled chart from data to display. This is the skeleton you'll reuse for almost every plot — create, draw, label, show.

The full recipe

a complete chart
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 200)
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(x, np.sin(x), label="sin")
ax.plot(x, np.cos(x), label="cos") # a second line
ax.set_title("Trig functions")
ax.set_xlabel("radians")
ax.set_ylabel("value")
ax.legend() # show the labels
ax.grid(True)
plt.show()

The reusable pattern

  • Create: fig, ax = plt.subplots()
  • Draw: ax.plot(...) (once per series, with a label=)
  • Label: title, axis labels, ax.legend()
  • Show or save: plt.show()

Key takeaways

  1. 01The core flow: create (subplots) → draw (ax.plot) → label → show.
  2. 02Overlay multiple series by calling ax.plot several times.
  3. 03Give each series a label= and call ax.legend() to identify them.
  4. 04figsize=(w, h) sets the figure size in inches.

Finished this chapter?

Mark it complete to track your progress through Matplotlib.