Setting labels to the groundtruth image of Remote sensing image

I am working on hyperspectral image classification. I am trying to plot groundtruth image using imshow function of matplotlib to get the groundtruth map. I am getting the color image but I want the labels of colors represented by the image. How can I get the labels along with the groundtruth image? Following is my code.
hsi_gt=sio.loadmat(“indian_pines_gt”)[‘indian_pines_gt’]
plt.imshow(hsi_gt)

If the data is quantative:

plt.colorbar()

If the data is categorical, then you’ll need to create the legend. Here’s an example modified from something I worked on:

import matplotlib.colors as mcolors
import matplotlib.cm as mcm
import matplotlib.patches as mpatches

# Create a custom color scheme for categories
colors = ["#FFCCCC", "#FFCC99", "#CCCCCC", 
          "#CC9933", "#99FFFF", "#66FFFF", 
          "#999999", "#CC9999", "#666666"]
mcmap = mcolors.ListedColormap(colors)
mnorm = mcolors.BoundaryNorm([200, 201, 211, 225, 237,239, 250, 254,255, 260], mcmap.N)

#provide labels for colors
labels = ['missing data', 'no decision', 'night', 
         'land', 'inland water', 'ocean', 
         'cloud', 'detector saturated', 'fill']
       
use those colors in your plot:
plt.imshow(mydata, cmap=cmap, norm=norm)

#create lwgend
patches = [mpatches.Patch(color=c, label=l) for c, l in zip(colors, labels)]
plt.legend(patches, labels, ncol=1, loc=6)