Why is it important to learn Matplotlib?

Question

Why is it important to learn Matplotlib for data science?

Answer

There are a few reasons why learning Matplotlib can be important for data science.

One reason is that it gives us the ability to visualize and present data in a clear and concise way with little code required. Because it utilizes Python, it is easy to read and write the code needed to create visualizations quickly and easily. With just the following line, we have access to many of the features of this powerful visualization library:
from matplotlib import pyplot as plt

Another reason is that being able to visualize our data lets us see patterns that otherwise might not be immediately clear in the actual raw data. If we are working with thousands or even millions of rows of data, as humans we can’t easily see connections.

Last but not least, Matplotlib provides many built-in functionality and figures we can draw such as barplots, histograms, scatterplots and much more. This lesson will provide an introduction to the library, so feel free to get started!

2 Likes

apologies not sure if this question should go here but do you know why we import pandas as follows:

Import pandas as pd

but matplotlib and some other tools this way:

from matplotlib import pyplot as plt

What tools do we have to say from for?

3 Likes

import module_name or import module_name as alias import a whole module (in your case, pandas.py)

while from will import a function or a class of a module. So matplotlib is the module, and pyplot is very likely a class.

using different import styles has consequences.

wouldn’t it just make sense then to import the whole module each time instead of a function or a class?

Lets build a whole library in our house, even though i only need to read 10 books.

3 Likes

cheers for the sarcasm but if it’s going to take a similar amount of time I don’t see what the negatives would be. If it’s going to take longer to load or something like that feel free to say instead of the petty analogy :slight_smile:

8 Likes

part of programming is knowing the different approaches, consider which approach is best and implement that. If you don’t know which approach to use and why (drawback vs advantage), its something which needs researching

anyway, not important yet. But something to consider for the future.

i think i was a couple of steps ahead, sorry :wink:

1 Like

I think that could definitely work for small projects,etc. But if you’re considering say a bigger project, like a big machine learning project, your code needs to be precise or else your program may get slower. Hence, we only import what we know is going to be needed rather than importing everything.

Can we import pyplot like this:
import matplotlib.pyplot as plt

Yes, that worked as well in the exercise.