Sitemap

Matplotlib Tutorial: How to Get Started With Matplotlib

3 min readOct 8, 2021

Hi everyone, welcome back. Matplotlib is a library for the Python programming language and is commonly used for data science and data visualization purposes. Matplotlib can be thought of a library that provides graph plotting functions that gives us visualization support. Let’s go over how you can get started with Matplotlib.

Press enter or click to view image in full size
Image

Installation

In order to work with Matplotlib, we will need to have Python and PIP installed onto our machines. Python can be downloaded and installed here and PIP can be downloaded and installed here. Once we have both Python and PIP installed, we can then install Matplotlib through the command line. Open up a command prompt or terminal and enter:

pip install matplotlib

Alternatively, Matplotlib can be downloaded and used through a Python distribution such as Anaconda or Spyder.

Importing

Now we want to import Matplotlib into our project to use. We can do this the same way we handle other imports by adding this line to our Python file:

import matplotlib

We can also import individual modules of Matplotlib into our project, for instance if we only want to import the Pyplot module, we can do so by adding this line to our file:

from matplotlib import pyplot

NumPy

NumPy is another library for Python that is commonly used for data science or statistical purposes. NumPy is short for “Numerical Python” and is used specifically to work with arrays and provides various functions regarding them. We will use NumPy arrays to store our plot points and use Pyplot to generate graphs based off of them. More about NumPy can read here.

Pyplot Basics

Let’s take a look at what Matplotlib can do. We’ll look at some of the basic functionality that Pyplot is capable of. Pyplot provides us with plotting and graph generating capabilities. Let’s see an example:

from matplotlib import pyplot
import numpy as np

x = np.array([0, 10])
y = np.array([0, 10])

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

Output:

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet