Plotting a DataFrame in Python
Pandas draws through matplotlib, and hands the axes back for finishing.
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
frame = pd.DataFrame(
{"python": [88, 92, 104], "rust": [80, 85, 91]},
index=pd.date_range("2026-07-27", periods=3, freq="D"))
figure, axes = plt.subplots()
frame.plot(ax=axes, marker="o")
axes.set_ylabel("tpm")
axes.grid(axis="y", alpha=0.3)
figure.savefig("frame.png")
print(type(axes).__name__)
How it works
frame.plotaccepts anaxso it joins a figure you built.- The index becomes the x axis by default.
- The returned axes is an ordinary matplotlib axes.
Keywords and builtins used here
asprinttype
The run, in numbers
- Lines
- 16
- Characters to type
- 392
- Tokens
- 135
- Three-star pace
- 110 tpm
At the three-star pace of 110 tokens a minute, this run takes about 74 seconds.
Step 4 of 4 in Reading the plot, step 13 of 14 in Plotting with matplotlib.