What is Matplotlib?

Matplotlib is an open-source Python library for 2D plotting. You can use it across Python environments ranging from simple Python scripts to interactive Jupyter notebooks.

Using Matplotlib has become easier with the availability of simple API calls for plotting all sorts of graphs.There are one line function calls for everything from line graphs to box plots. (Just a line of code! Sounds groovy, right 😉?)

Matplotlib also has a large community that helps Matplotlib users with various types of technical queries and questions.

Lastly, upcoming plotting libraries that have more aesthetic appeal than the veteran Matplotlib are also built on top of Matplotlib. Seaborn is one such example. Even the internal plotting commands in Pandas use Matplotlib under the hood.

Who uses Matplotlib?

Using graphs to convey the final results of a data science project is a standard practice. Visualizations help simplify complex technical details, which business teams can interpret easily.

Data analysts use Matplotlib to visually examine trends and statistics in large datasets and draw relevant insights.

Machine learning engineers use Matplotlib to monitor their model’s performance via metrics such as training loss and testing loss by plotting their reduction over time.

How can you get started with Matplotlib?

Installing Matplotlib

If you use pip, then type the following command to install Matplotlib as part of your Python environment:

python -m pip install -U matplotlib

If you use Anaconda, then you don’t have to install anything since it comes pre-installed with the latest version of Matplotlib.

Once installed, import Matplotlib in your Python shell with the following command:

import matplotlib.pyplot as plt

After the import, you can start plotting.

Plotting a line graph

Run the following command to plot a simple line graph:



  1. plt.plot() - plot function in Matplotlib
  2. [1,2,3] - a list of values for the X-axis
  3. [4,5,6] - a list of corresponding values for the Y-axis
A line graph for the X-axis coordinates [1,2,3] and Y-axis coordinates [4,5,6]

To learn more about the various functions that Matplotlib offers, you can go through the official Matplotlib User Guide.

Think we're missing something? 🧐 Help us update this article by sending us your suggestions here. 🙏

See also

Articles you might be interested in

  1. Matplotlib tutorial: Python plotting
  2. Matplotlib crash course Python tutorial
  3. Matplotlib - Github source code