3 ms·
I find using this library really confusing because of the two different APIs -matlplotlib.pyplot and the figures and axes of created plots. Documentation and o
by oli5679 4y ago
I find using this library really confusing because of the two different APIs -matlplotlib.pyplot and the figures and axes of created plots.
Documentation and other peoples' code seems to jump between the two. It's a really good example of the downsides of having too many ways to do the same thing in the same library.
- santiagobasulto 4y agoFigures and axis is the OOP interface, and what I always recommend. Pyplot is a global namespace procedural interface similar to matlab. If you find an example online using pyplot, it’s easy to find the axis. counterpart. For example, plt.title() becomes axis.set_title(). Axes and Figure reference API docs are very good.
- jbay808 4y ago> Figures and axis is the OOP interface, and what I always recommend. No doubt, but half the time when I am looking online for how to do something off the beaten path, I find a documentation page or stackoverflow answer that (only) uses the other interface, and I have to flail about for a while to come up with the OOP equivalent.
- squaresmile 4y agoYep, I think the reference documentation is quite good. I always direct people to the quick start [0] and then look at the examples [1] to see how things are done. All examples have the plots and self-contained scripts so it's intuitive to search for what you want even if it's hard to describe or google. [0] https://matplotlib.org/stable/tutorials/introductory/quick_start.html https://matplotlib.org/stable/tutorials/introductory/quick_s... [1] https://matplotlib.org/stable/gallery/index.html https://matplotlib.org/stable/gallery/index.html
- Foivos 4y agoI had the same problem until I found this tutorial: https://github.com/rougier/matplotlib-tutorial https://github.com/rougier/matplotlib-tutorial If you wan something deeper the same person has written a book: https://github.com/rougier/scientific-visualization-book https://github.com/rougier/scientific-visualization-book
- quietbritishjim 4y agoThe comment you're replying to has a very specific concern: the difference between the OO and static APIs. The page you linked to didn't appear to address that, it's just a general tutorial. In fact, I can't even find where it mentions that aspect... It seems to assume you already know about that as a prerequisite.
- Foivos 4y agoYou are right. It does not address this concern specifically, but if you follow this tutorial to learn this library, hopefully, you will not get to have this concern. Regarding the different APIs, this page [1] from the documentation attempts to compare them and provide code that generates the same result using the the different APIs. [1] https://matplotlib.org/devdocs/users/explain/api_interfaces.html https://matplotlib.org/devdocs/users/explain/api_interfaces....
- patrick451 4y agoI don't think that two ways to do something is too many. It's nice to be able to just throw a plot on the screen with plt.plot(), but it's also nice to have the extra control the figure/axes OO interface gives you. Matlab works the same way.
- markrages 4y agoIt's in the name - a copy of Matlab's procedural API. So matplotlib is popular because they copied Matlab's original mistake. (The procedural / global state API is actually reasonable for interactive plotting from a REPL.)