Visualizing Satellite Imagery with Matplotlib

Taking a closer look at satellite data with Python

In the Inspecting Satellite Imagery Notebook, we learned how to use Rasterio to read and manipulate satellite data. There we also learned that, since satellite images are really grids of pixel-values, a satellite image can be interpreted as a multidimensional array of values.

You may already be familiar with the Python library matplotlib: here, we're going to briefly use that toolset to visually plot satellite data that has been read into a numpy array using Rasterio.

In [1]:
import rasterio
from matplotlib import pyplot as plt

# This notebook explores a single 4 band (blue, green, red, NIR) PlanetScope scene in a UTM projection.
image_file = "example.tif"

# Use Rasterio to open the image.
satdat =

In [2]:
# Load the 4 bands into 2d arrays - recall that we previously learned PlanetScope band order is BGRN.
b, g, r, n =

In [3]:
# Use imshow to load the blue band.
fig = plt.imshow(b)

# Display the results.

In [4]:
# Plot the green band using a non-default color ramp.
fig = plt.imshow(g)

# Display the results.

In [5]:
# Plot the red band and add a color bar.

fig = plt.imshow(r)

# Display the results.

In [6]:
# Finally, plot the NIR band.
fig = plt.imshow(n)

# Since the axis labels are useless here, let's turn them off.

# Display the results.