I'm not really new to matplotlib
and I'm deeply ashamed to admit I have always used it as a tool for getting a solution as quick and easy as possible. So I know how to get basic plots, subplots and stuff and have quite a few code which gets reused from time to time...but I have no "deep(er) knowledge" of matplotlib
.
Recently I thought I should change this and work myself through some tutorials. However, I am still confused about matplotlibs plt
, fig(ure)
and ax(arr)
. What is really the difference?
In most cases, for some "quick'n'dirty' plotting I see people using just pyplot as plt
and directly plot with plt.plot
. Since I am having multiple stuff to plot quite often, I frequently use f, axarr = plt.subplots()
...but most times you see only code putting data into the axarr
and ignoring the figure f
.
So, my question is: what is a clean way to work with matplotlib? When to use plt
only, what is or what should a figure
be used for? Should subplots just containing data? Or is it valid and good practice to everything like styling, clearing a plot, ..., inside of subplots?
I hope this is not to wide-ranging. Basically I am asking for some advice for the true purposes of plt
<-> fig
<-> ax(arr)
(and when/how to use them properly).
Tutorials would also be welcome. The matplotlib documentation is rather confusing to me. When one searches something really specific, like rescaling a legend, different plot markers and colors and so on the official documentation is really precise but rather general information is not that good in my opinion. Too much different examples, no real explanations of the purposes...looks more or less like a big listing of all possible API methods and arguments.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…