Every object Axes
has an object Figure
which contains it (starting from the principle that it was initialized correctly). A Figure
may contain multiple Axes
, in the case of a figure with more than one graph. To display a Figure
on screen, use:
figure.show()
In case you only have access to Axes
, it is possible to pick up your Figure
corresponding with:
ax.get_figure()
It is worth noting that the module pyplot
is a shortcut that aims to facilitate this interface of elements: you can take the Figure
current (i.e., last modified) with pyplot.gcf()
, plot in the Axes
current with pyplot.plot()
and show the Figure
current with pyplot.show()
. Accessing the graphical elements Figure
and Axes
directly is more labor intensive and should only be used if you really need this control.
In your case, call DataFrame.plot()
is even higher level than using the pyplot
: pandas itself cares to call/initialize the matplotlib elements for you. In general, to avoid the verbosity of something like:
ax = df.plot( ... )
ax.get_figure().show()
Prefer:
df.plot( ... )
plt.show()
Having previously imported the pyplot
with the convention import matplotlib.pyplot as plt
.
Here is a more detailed description of the elements that make up a Axis
.
Here talks a little more about the functioning of the module pyplot
.
Great. It worked, that’s right. I had read a lot of documents without getting results. You have managed to explain the basics to me and direct me in the right direction to read what is needed. Now the rest is up to me. Thank you.
– j6ninhas