Open In App

How to import matplotlib in Python?

Last Updated : 21 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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).

  1. Open your command prompt or terminal.
  2. Run the following command to install Matplotlib:

pip install matplotlib

Screenshot-2025-04-21-190632
Installing 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:

import-matplotlib
installing/importing Matplotlib

Let's create a simple line chart after successfully importing matplotlib to verify the installation:

Python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]

plt.plot(x, y)
plt.show()

Output:

Screenshot-2024-11-28-160115
SImple line chart on Matplotlib

For more details you can refer to:


Next Article

Similar Reads