pyplot (Matplotlib)
pyplot is Matplotlib's MATLAB-style interface, imported as plt, that provides simple functions like plt.plot() and plt.show(). It keeps track of a 'current' figure and axes so you can plot with minimal setup.
Matplotlib
The conventional import is import matplotlib.pyplot as plt. pyplot offers a stateful, command-driven API: each call (plt.plot, plt.title, plt.xlabel) acts on whichever figure and axes are 'current', which it manages behind the scenes. This makes quick, single-plot scripts very terse.
That hidden state is also pyplot's weakness. For complex figures with multiple subplots it becomes ambiguous which axes a command targets, which is why the object-oriented style — calling methods on explicit Figure and Axes variables — is recommended for anything beyond a quick chart.
Many people use a hybrid: plt.subplots() to create the Figure and Axes (a pyplot helper), then methods on those objects for everything else. plt.show() and plt.savefig() remain handy pyplot conveniences either way.
Syntax
import matplotlib.pyplot as plt; plt.plot(x, y); plt.show()Examples
Python — plt.gca() returns the current Axes pyplot is drawing on.
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
print(type(plt.gca()).__name__)Output:
Axes