Under the Hood: Matplotlib
A Look Under the Hood: Matplotlib. When you call
.plot() on a
DataFrame object, Matplotlib creates the plot under the hood. To verify this, try out two code snippets.
Firstly, create a plot with Matplotlib using two columns of your DataFrame. Firstly, the
matplotlib.pyplot module is imported as
.plot() is called passing the
"Rank" column as the first argument and
"P75th" column as the second argument.
The result is a line graph that plots the 75th percentile on the y-axis against the rank on the x-axis. You can create exactly the same graph using the
.plot() is a wrapper for
pyplot.plot(), and the result is a graph identical to the one you produced with Matplotlib directly. You can use
df.plot() to produce the same graph from columns of a
DataFrame object. However, if you already have a
DataFrame instance, then
DataFrame.plot() offers a cleaner syntax than
If you’re already familiar with Matplotlib, then you may be interested in the
kwargs parameter to
.plot(). You can pass it a dictionary containing keyword arguments that will then be passed on to Matplotlib’s plotting backend. For more information on Matplotlib, check out Real Python’s Python Plotting With Matplotlib course.
Now that you know the
.plot() method is a wrapper for Matplotlib’s
pyplot.plot(), let’s dive into the different kinds of plots you can create and how to make them.
Become a Member to join the conversation.