Skip to content
LearnPY
Matplotlibfunction reference

Axes.plot

Draw lines and markers on an axes.

Signature

Axes.plot(*args, label=None, color=None)

What it does

Axes.plot connects x/y pairs with a line by default. A format string such as "o--" chooses markers and line style. Repeated calls on the same axes overlay additional series.

Parameters

x, yarray_like
The horizontal and vertical values to plot.
labelstr, optionaloptional
Legend label for the series.
colorcolor, optionaloptional
Line or marker color.

Returns

list of Line2D

Example

pythonAxes.plot example
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [3, 1, 2], marker="o", label="scores")
ax.plot([1, 2, 3], [2, 2, 3], linestyle="--", label="target")
ax.legend()

Watch out for

  • Plotting without an explicit axes uses the current global axes, which can surprise you in larger scripts.
  • If x is omitted, plot uses the indices of y as the x values.