In This Lesson

Learning Objectives

After completing this tutorial, you will be able to:

Overlay 2 rasters in Python to create a plot.

What You Need

You need Python and Jupyer Notebook to complete this tutorial. You should also have an earth-analytics directory setup on your computer with a data subdirectory within it. You should have completed the lesson on Setting Up the Conda Environment..

importrasterioasrioimportnumpyasnpimportmatplotlib.pyplotaspltimportosimportearthpyasetplt.ion()# Set working directoryos.chdir(os.path.join(et.io.HOME,'earth-analytics'))

Overlay Rasters in Python

In this lesson, you will learn about overlaying rasters on top of a hillshade for nicer looking plots in python. To overlay a raster will will plot two different raster datasets in the same plot in matplotlib. You will use alpha to adjust the transparency of one of your rasters so the terrain hillshade gives the raster texture! Also you will turn of the legend for the hillshade plot as the legend we want to see is the DEM elevation values.

What is a Hillshade?

A hillshade is a representation of the earth’s surface as it would look with shade and shadows from the sun. You often render a hillshade using a greyscale colorramp.

Hillshades make nice underlays for other data as they emphasize the topography visually. This adds depth to your map!

To begin, open up both the Digital Terrain Model and the Digital terrain model hillshade files.

To plot both layers together, you add a alpha value to the dem image. This value makes the image more transparent. Below an alpha of .5 (50%) is applied. Play around with the alpha value to see how it impacts your map.

fig,ax=plt.subplots(figsize=(10,6))ax.imshow(lidar_dem_hill,cmap='Greys')fin_plot=ax.imshow(lidar_dem_im,cmap='viridis_r',alpha=.5)fig.colorbar(fin_plot,fraction=.024,pad=.02)ax.set_axis_off()ax.set(title="Lidar Digital Elevation Model (DEM)\n overlayed on top of a hillshade");