Question
Should we always import Matplotlib when using the Seaborn module?
Answer
The short answer is yes, you should always import Matplotlib if you are using Seaborn.
Seaborn is built on top of Matplotlib. It is an extension to it, and not a substitute. It builds on top of Matplotlib, introducing some additional plot types and provides some visual improvements to some plots and graphs.
However, on its own Seaborn doesn’t have all the functionality that Matplotlib provides, including the ability to change some defaults applied by Matplotlib.
We still need Matplotlib if we want to do things like changing the plot title or tick labels, and adding a legend. Matplotlib just makes it easier for us to do these things alongside Seaborn.
Also, we still need to have plt.show()
because plots creating using seaborn must be displayed like Matplotlib plots. In some versions, Seaborn does allow you to do sns.plot.show()
, but this is considered bad practice, and you should use plt.show()
from Matplotlib instead.