Pandas vs Matplotlab for graphs

Hello,
I had a question on the “Pandas Visualisations and Grid Charts Mission” on Page 4.

URL: Learn data science with Python and R projects

Up until now we have been using matplotlab.pyplot for graphs (i.e. plt.bar())? Now, we have been introduced to pandas to make graphs (i.e., series.plot.hist()).

Is pandas preferred over matplotlib when making graphs. Are there pros and cons to using one over the other? Can we just use or or the other?

1 Like

Pandas uses Matplotlib behind the curtains to generate the graphs, so there’s no difference in terms of output — what you get with Pandas, you can get with Matplotlib.

Using Pandas visualization methods can be quicker if your data comes in the form of Pandas objects, like Series or DataFrame. When you’ve just read in a dataset and want to explore it using data visualization, using Pandas visualization methods will make you work faster. The Pandas visualization ecosystem is quite complex — see a full tutorial here.

Matplotlib is great for advanced graph customization (see the Storytelling Data Visualization and Information Design course) or for creating graphs out of non-Pandas objects.

All in all, feel free to use what you’re accustomed with. One of the reasons we teach both ways is that learners need to know to at least read both — although they can only use one to generate their own graphs.

2 Likes

Thanks @alex for the response!

1 Like

in addition in the pandas visualizations and Grid chart lesson it was indicated this statement

However, we’re going to use plt.plot() instead of the DataFrame.plot.line() method. That’s because DataFrame.plot.line() plots separate graphs by default, which means we won’t be able to put all the lines on the same graph.

<<Learn data science with Python and R projects