why create figure()
and calling add_axes()
while plotting instead of a straight forward plot()
in matplotlib. Is there any benefits to using the former approach?
CodePudding user response:
This is used for Sub Plots wehn you have more than one plot or graphs.
CodePudding user response:
As explained in matplotlib blog, the benefits of OO approach are scalability and control. The functional interface (pyplot) was build to reproduce MATLAB's method of generating figures, which is a very popular propetary programing language in engeenering departments. Pyplot works as a state-based interface, where the states are figures that can be changed by methods.
On the other hand, in the OO approach Figure are just the top level container (object) that holds many elements called Artists. This garantee whole control of the elements showed in the final Figure, like tick values, markers, grid, and so on.
To get in touch with more detailed information on this subject, i recommend that you take a look at the following links:
The Lifecycle of a Plot: https://matplotlib.org/matplotblog/posts/pyplot-vs-object-oriented-interface/
Matplotlib Guide from Real Python: https://realpython.com/python-matplotlib-guide/