Set values you dont want to show to np.nan
:
import rasterio
from matplotlib import pyplot as plt
slope_raster = r"C:\gistest\minislope.tif"
import numpy as np
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(10,20))
src = rasterio.open(slope_raster)
arr = src.read(1)
ax1.set_title("Original slope raster")
ax1.imshow(arr)
ax2.set_title("Slopes greater than 20 % masked")
arr2 = arr.copy()
arr2[arr2>20] = np.nan
ax2.imshow(arr2)