How to Install matplotlib in Python
Python plotting package
pip install matplotlib
What is matplotlib?
Python plotting package
Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python.
Check out our home page for more information.
Matplotlib produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, Python/IPython shells, web application servers, and various graphical user interface toolkits.
Quick Start
Minimal example to get started with matplotlib:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2 * np.pi, 100)
plt.plot(x, np.sin(x), label="sin(x)")
plt.plot(x, np.cos(x), label="cos(x)")
plt.legend()
plt.title("Trigonometric Functions")
plt.show()
Installation
pip (standard)
pip install matplotlib
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install matplotlib
pip3
pip3 install matplotlib
conda
conda install -c conda-forge matplotlib
Poetry
poetry add matplotlib
Dependencies
Installing matplotlib will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import matplotlib; print(matplotlib.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing matplotlib with pip.
ModuleNotFoundError: No module named 'matplotlib'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install matplotlib. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'matplotlib' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install matplotlib to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'matplotlib'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show matplotlib and upgrade with pip install --upgrade matplotlib.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install matplotlib. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user matplotlib
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org matplotlib
MemoryError when loading data
Cause: Dataset is too large to fit in RAM.
Fix: Read in chunks, filter columns on load, or consider Polars/Dask for out-of-core processing.
Recent Releases
| Version | Released |
|---|---|
3.10.8 latest |
2025-12-10 |
3.10.7 |
2025-10-09 |
3.10.6 |
2025-08-30 |
3.10.5 |
2025-07-31 |
3.10.3 |
2025-05-08 |
Manage matplotlib
Upgrade to latest version
pip install --upgrade matplotlib
Install a specific version
pip install matplotlib==3.10.8
Uninstall
pip uninstall matplotlib
Check what is installed
pip show matplotlib