How to Install Matplotlib in Python
Matplotlib is one of the most popular open-source Python libraries used for data visualization. It allows Python programmers to create different types of charts, graphs, and plots from data. With Matplotlib, you can create bar graphs, line charts, scatter plots, histograms, pie charts, area plots, and many other visualizations.
Data visualization makes it easier to understand large amounts of information. Instead of looking at raw numbers, you can represent data visually and quickly identify patterns, differences, trends, and relationships. This is especially useful in data science, machine learning, business analytics, research, and Python projects.
Before creating your first graph with Matplotlib, you need to install the library in your Python environment. Fortunately, installing Matplotlib is simple and can be done using different methods depending on the Python setup you are using.
In this guide, you will learn how to install Matplotlib in Python using pip, Anaconda, Conda, Command Prompt, and common Python development environments.
Table of Contents

Complete Advance AI Topics: Click Here
Complete Python Course with Advance Topics: Click Here
What is Matplotlib in Python?
Matplotlib is a Python library designed for creating static, animated, and interactive visualizations. It provides different functions and modules that make it possible to convert numerical or categorical data into useful graphical representations.
For example, if you have monthly sales data, you can use Matplotlib to create a line chart or bar chart. This makes it much easier to understand how sales changed from one month to another.
A simple Matplotlib program looks like this:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 15, 25]
plt.plot(x, y)
plt.show()
Before running this program, Matplotlib must be installed in your Python environment.
Prerequisites Before Installing Matplotlib
Before installing Matplotlib, make sure Python is already installed on your computer. You can check the installed Python version by opening Command Prompt or Terminal and running:
python --version
On some systems, you may need to use:
python3 --version
If Python is installed correctly, the command will display your Python version.
How to Install Matplotlib in Python Using pip
The most common method for installing Matplotlib is using pip. Pip is Python’s package manager and allows you to install Python libraries directly from the command line.
Step 1: Open Command Prompt or Terminal
On Windows, open Command Prompt or PowerShell. On macOS and Linux, open the Terminal.
Step 2: Install Matplotlib
Type the following command and press Enter:
pip install matplotlib
Pip will download Matplotlib and install the required packages automatically.
Step 3: Wait for Installation
After the installation is complete, you should see a message indicating that Matplotlib and its dependencies have been installed successfully.
If your system does not recognize the pip command, try:
python -m pip install matplotlib
This command is often useful when multiple Python versions are installed on the computer.
How to Install Matplotlib in Python on Windows 10 and Windows 11
Installing Matplotlib on Windows 10 or Windows 11 is straightforward. First, make sure Python is installed. Then open Command Prompt and run:
pip install matplotlib
If this command does not work, use:
python -m pip install matplotlib
After installation, you can verify it by opening Python and importing Matplotlib.
import matplotlib
print(matplotlib.__version__)
If a version number is displayed, Matplotlib has been installed successfully.
How to Install Matplotlib Using Anaconda
Anaconda is a popular Python distribution used by students, developers, data scientists, and machine learning professionals. It provides many commonly used Python libraries and tools in one environment.
If you are using Anaconda, Matplotlib may already be available in your environment. You can use tools such as Jupyter Notebook or Spyder to work with Python and create visualizations.
If Matplotlib is not available, you can install it using the Conda package manager.
Install Matplotlib with Conda
Open Anaconda Prompt and enter:
conda install matplotlib
Conda will resolve the required dependencies and install Matplotlib in the selected environment.
How to Install Matplotlib in Jupyter Notebook
If you are working with Jupyter Notebook, you can install Matplotlib from a notebook cell using pip.
!pip install matplotlib
After the installation finishes, import Matplotlib in another cell:
import matplotlib.pyplot as plt
You can then create your first graph:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [5, 10, 15, 20]
plt.plot(x, y)
plt.show()
This will display a simple line graph in your Jupyter Notebook.
How to Install Matplotlib in VS Code
Visual Studio Code is another popular environment for Python programming. To install Matplotlib in VS Code, open the integrated terminal and run:
pip install matplotlib
After installation, create a Python file such as matplotlib_example.py and write:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 15, 20, 25]
plt.plot(x, y)
plt.show()
Run the Python file from VS Code. If the graph appears without an import error, Matplotlib is working correctly.
Make sure VS Code is using the same Python interpreter or virtual environment where Matplotlib was installed.
How to Install Matplotlib in Python IDLE
Python IDLE itself does not normally install third-party libraries. You can install Matplotlib using Command Prompt first.
Open Command Prompt and run:
python -m pip install matplotlib
After installation, open Python IDLE and test the library:
import matplotlib
print(matplotlib.__version__)
If there is no error and the version number is displayed, Matplotlib is ready to use in IDLE.
How to Verify Matplotlib Installation
After installing Matplotlib, it is a good idea to verify that the library is working correctly.
Open Python and run:
import matplotlib
print(matplotlib.__version__)
You should get a version number as output. The exact version may be different depending on when you install Matplotlib.
You can also test Matplotlib by creating a small graph:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [10, 20, 30]
plt.plot(x, y)
plt.title("My First Graph")
plt.xlabel("X Values")
plt.ylabel("Y Values")
plt.show()
If the graph opens successfully, your Matplotlib installation is working.
Common Matplotlib Installation Error
No Module Named ‘matplotlib’
One common error beginners may see is:
ModuleNotFoundError: No module named 'matplotlib'
This usually means Matplotlib is not installed in the Python environment currently being used.
Try installing it with:
python -m pip install matplotlib
If you are using a virtual environment, activate that environment first and then install Matplotlib.
In VS Code, also check that the selected Python interpreter is the same environment where you installed Matplotlib.
YT:- DecodeIT
Matplotlib Installation Methods at a Glance
| Method | Command or Tool | Suitable For |
|---|---|---|
| pip | pip install matplotlib | Standard Python installation |
| Python pip | python -m pip install matplotlib | Multiple Python installations |
| Conda | conda install matplotlib | Anaconda users |
| Jupyter | !pip install matplotlib | Jupyter Notebook users |
Why Use Matplotlib?
Matplotlib is widely used because it provides a simple way to visualize data directly from Python programs. It can be used for basic charts as well as more detailed data visualization tasks.
- Create different types of graphs and charts.
- Visualize numerical and categorical data.
- Add titles, labels, legends, and other chart elements.
- Customize the appearance of plots.
- Use it with data science and machine learning projects.
- Work with libraries such as NumPy and Pandas.
- Use it in Jupyter Notebook, VS Code, and other Python environments.
Matplotlib is therefore a useful library for students who are learning Python, data analysis, and machine learning.
Conclusion
Installing Matplotlib is one of the first steps toward learning data visualization with Python. The easiest method for most Python users is to use pip install matplotlib. Anaconda users can use the Conda package manager, while Jupyter Notebook users can install the library directly from a notebook cell.
Once Matplotlib is installed, you can create line charts, bar graphs, scatter plots, histograms, pie charts, and many other visualizations. If you face a No module named 'matplotlib' error, check that Matplotlib is installed in the correct Python environment.
With Matplotlib successfully installed, you are ready to start exploring Python data visualization and build useful charts for your data science and machine learning projects.
Frequently Asked Questions (FAQ)
1. What is the command to install Matplotlib in Python?
The most common command is:
pip install matplotlib
2. How can I install Matplotlib on Windows?
Open Command Prompt and run pip install matplotlib. If pip is not recognized, try python -m pip install matplotlib.
3. How do I install Matplotlib in Jupyter Notebook?
You can run !pip install matplotlib in a Jupyter Notebook cell and then import the library using import matplotlib.pyplot as plt.
4. How do I install Matplotlib in VS Code?
Open the VS Code terminal and run pip install matplotlib. Make sure VS Code is using the Python environment where Matplotlib was installed.
5. How can I check whether Matplotlib is installed?
Run import matplotlib followed by print(matplotlib.__version__). If the version number appears, Matplotlib is installed.
6. Why am I getting “No module named matplotlib”?
This error generally occurs when Matplotlib is not installed in the active Python environment. Install it using python -m pip install matplotlib and make sure you are using the correct environment.
7. Can I install Matplotlib using Anaconda?
Yes. Open Anaconda Prompt and use conda install matplotlib to install Matplotlib in your Conda environment.
Related Keywords
how to install matplotlib in python, pip install matplotlib, how to install matplotlib in python windows 10, how to install matplotlib in python windows 11, how to install matplotlib in python jupyter notebook, how to install matplotlib in python using command prompt, how to install matplotlib in python vscode, how to install matplotlib in python idle, no module named matplotlib, matplotlib in python, install pip in python, install sklearn in python, online python compiler, install matplotlib in python w3schools
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.