typestar

Line plots in Python

Several series on one axes, each with its own style and label.

import matplotlib

matplotlib.use("Agg")
import matplotlib.pyplot as plt

days = [1, 2, 3, 4, 5]
python = [88, 91, 97, 104, 108]
rust = [80, 84, 88, 90, 95]

figure, axes = plt.subplots()
axes.plot(days, python, label="python", marker="o")
axes.plot(days, rust, label="rust", linestyle="--", linewidth=2)
axes.set_xlabel("day")
axes.set_ylabel("tpm")
axes.set_title("tokens per minute")
axes.legend(loc="lower right")
figure.savefig("lines.png")

How it works

  1. Every plot call takes a label, and the legend reads them.
  2. linestyle, marker and linewidth are the usual knobs.
  3. set_xlabel and friends name the axes for the reader.

Keywords and builtins used here

The run, in numbers

Lines
17
Characters to type
445
Tokens
150
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 86 seconds.

Type this snippet

Step 1 of 5 in Plot types, step 5 of 14 in Plotting with matplotlib.

← Previous Next →