How to import matplotlib in Python?
Matplotlib is a Python library used to create different types of charts and graphs. It helps to turn data into visual formats like line charts, bar graphs and histograms. This makes it easier to understand and present your data. In this guide you’ll learn how to install and import Matplotlib in Python step by step.
Step 1: Install Matplotlib
Before using Matplotlib you need to make sure it is installed on your computer. You can install it using pip
(Python's package installer).
- Open your command prompt or terminal.
- Run the following command to install Matplotlib:
pip install matplotlib

Step 2: Import Matplotlib - Add the import module statement
After installation you can import Matplotlib in your Python code. The common way is to import its pyplot module like in below image:

Let's create a simple line chart after successfully importing matplotlib to verify the installation:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
plt.plot(x, y)
plt.show()
Output:

For more details you can refer to: