Plot the Arrays

Learn how to plot arrays using the matplotlib library.

We'll cover the following

Use of matplotlib

Just like large tables or lists of numbers, looking at large arrays isn’t that helpful. Visualizing them helps us quickly get an idea of the general meaning. One way of plotting two-dimensional arrays of numbers is to think of them as flat two-dimensional surfaces, colored according to the value at each cell in the array. We can choose how we turn a value inside a cell into a color. We might choose to simply turn the value into a color according to a color scale, or we might color everything white except for values above a certain threshold that would be black.

Coding example

Let’s try plotting the small 3×23 \times 2 array we created above.

Before we can do this, we need to extend Python’s abilities to plot graphics. We do this by importing additional Python code that others have written. We can think of this like borrowing a recipe books from our friend, enabling us to prepare more dishes than we could before.

The following code shows how we import the graphics plotting capability:

Get hands-on with 1200+ tech skills courses.