Skip to content

Installing Matplotlib

Installing Matplotlib

Matplotlib must be installed in the working Python environment before it can be used. There are three different ways to install Matplotlib:

  • Install Matplotlib with the Anaconda distribution of Python
  • Install Matplotlib with the Anaconda Prompt
  • Install Matplotlib with pip

Install Matplotlib with the Anaconda distribution of Python

If you downloaded and installed the Anaconda distribution of Python, Matplotlib came with it and therefore Matplotlib is already installed. No further installation is necessary unless a separate virtual environment is used. If you do not have the Anaconda distribution of Python, Matplotlib can be installed by downloading and installing the Anaconda distribution of Python, as the Matplotlib is part of the distribution.

Installing Matplotlib with the Anaconda Prompt

To install matplotlib with the Anaconda Prompt, open the Anaconda Prompt and type:

> conda install matplotlib

Type y for yes when prompted.

Installing Matplotlib with pip

To install Matplotlib with pip (the Python package manager), open a terminal window and type:

$ pip install matplotlib

This command installs Matplotlib in the current working python environment. Once installed, you can confirm Matplotlib is available for import by opening up the Python REPL or a Jupyter notebook and typing:

In [1]:
>>> import matplotlib
>>> matplotlib.version

Out[1]:
'2.1.2'

Once Matplotlib is installed, you can start building line plots, bar charts, pie charts, and scatter plots. Each of these plot types will be described in a different section of this chapter. The simplest kind of plot to build with Matplotlib is a line plot. A simple line plots is the first type of plot we'll create.