Figures, Axes, and the plotting interface
3.11.2
Create a figure and draw on an Axes object using the explicit plotting interface.
On this page
Figure, Axes, and Axis
A Figure contains one or more plotting areas called Axes. Each Axes has Axis objects that handle ticks and scales. Use the object-oriented interface when building several charts or sharing code.
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [6, 9, 8], marker="o")
ax.set(title="Orders by month", xlabel="Month", ylabel="Orders")
plt.show()
Download image
Identify the parts of a chart
The Figure is the whole canvas, including the margins. The Axes is the chart area that contains the plotted line and points. The x-axis and y-axis encode the scales. The title describes the chart and the axis labels give the meaning of the values.
Download image
Display or save a figure
plt.show() displays open figures in an interactive environment. A headless script can save the Figure to a file. Save before a blocking show when using pyplot, or retain the Figure and call its savefig method.