We will cover both approaches here, but will focus more on object-oriented approach, since this is consistent with the rest of Python, and is the approach recommended by most people, including Matplotlib’s official documentation. For example, pandas DataFrames are objects - they contain data, but they also have a set of methods that can operate on the data (e.g., df.plot(), df.merge()). In contrast, object-oriented programming is based around objects, which can have both data and methods in them. Procedural programming is based around variables, data structures, and procedures - ways of operating on variables and data structures. However, the two approaches are fundamentally different, and thus attempts to use snippets of code that you see in some examples may create errors, if you attempt to combine Matplotlib’s functional and object-oriented approaches to generate a single figure. you may see two rather different ways of doing the same thing, often with what may appear to be only subtle differences in the code. This means that when you encounter examples using Matplotlib “in the wild” - be that other people’s code, tutorials, blog posts, etc. Subsequently however, an object-oriented approach was implemented as well. Thus in pursuing its initial goal of emulating Matlab’s plotting functions, Matplotlib implemented a functional approach to generating plots. Python is an object-oriented language, however Matlab is a functional language. These have been mentioned earlier, in the context of comparing programming languages: procedural and object-oriented. One of the most confusing things about learning Matplotlib is that it supports two fundamentally different ways of approaching plotting. object-oriented uses of MatplotlibĪppropriately choose between and use these approaches Understand the difference between procedural and object-oriented programming ![]() ![]() Why do these various plot commands I copied from a Stack Overflow post not work? Why are there two different ways of generating plots with Matplotlib? What is the difference between plt.plot() and ax.plot()? Procedural versus Object-Oriented Plotting in Matplotlib # Reading and Visualizing Structural MRI Data. ![]()
0 Comments
Leave a Reply. |