Matplotlib Object-Oriented Approach
Let’s learn about the object-oriented approach in matplotlib.
We'll cover the following
We’ve already seen how to do basic plotting. However, it’s generally recommended to use an object-oriented approach because it allows us much more control over our plots, as well as more customization options.
Let’s break down and learn the formal introduction of Matplotlib’s object-oriented API for plotting data.
The idea behind the object-oriented approach is that we create figure objects and then call methods or attributes from that object. This elegant approach is helpful when we are dealing with a canvas that has multiple plots on it.
To start, let’s create a figure instance
fig1
and add axes to that figure:
Get hands-on with 1400+ tech skills courses.