Object-oriented guide to matplotlib
Matplotlib provides two distinct interfaces for users. The stateful interface makes all of its calls with the pyplot
module. This interface is called stateful because matplotlib keeps track internally of the current state of the plotting environment. Whenever a plot is created in the stateful interface, matplotlib finds the current figure or current axes and makes changes to it. This approach is fine to plot a few things quickly but can become unwieldy when dealing with multiple figures and axes.
Matplotlib also offers a stateless, or object-oriented, interface in which you explicitly use variables that reference specific plotting objects. Each variable can then be used to change some property of the plot. The object-oriented approach is explicit, and you are always aware of exactly what object is being modified.
Unfortunately, having both options can lead to lots of confusion, and matplotlib has a reputation for...