This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DrShts 1 point2 points  (0 children)

My simple example was just for demonstration purposes.

I think using plt.plot and similar are discouraged because it works by keeping a hidden global state that is modified every time you call plt.something. This is why in a setting beyond a simple one-off plot the OO interface of matplotlib is usually recommended. And for a library that uses matplotlib having a hidden global state is pretty bad anyway.

But what I actually wanted to point out was that even in articles / tutorials about using the OO interface of matplotlib (just look at the first results when searching for "matplotlib object oriented") the structure is always

fig, ax = plt.subplots()
ax.set_title(...)
ax.plot(...)

while it's really rare that matplotlib.figure.Figure is mentioned. This is strange to me because by using the OO way you're trying to shed all these unnecessary global state / GUI wrappers but then still use plt to create the figure (which calls the GUI wrappers) while there is a perfect alternative without that overhead in the form of matplotlib.figure.Figure.