Matplotlib's pyplot documentation says as follow,
pyplot matplotlib.pyplot is a state-based interface to matplotlib.
What is meant by state-based interface to matplotlib
In the pyplot tutorial it says
In matplotlib.pyplot various states are preserved across function calls, so that it keeps track of things like the current figure and plotting area, and the plotting functions are directed to the current axes
As an example:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,6,5])
This puts pyplot in a state where a current figure and a current axes is defined. Subsequently issuing some other pyplot command like
plt.title("My title")
will set the title of the current axes that is stored in the pyplot state. Finally,
plt.show()
will show all the figures stored in the pyplot state. (Also relevant: How does plt.show() know what to show?)
So in total, the state-based interface means that pyplot has a couple of functions, which will act on a currently defined state. This is fundamentally different to an object-oriented approach, where object methods are used:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot([1,2,3],[4,6,5])
ax.set_title("My Title")
Here, different objects' methods are used to create new content. (Still the figure is created via pyplot, such that it can eventually be shown via plt.show()
.)