Q:

I want to change the color of image in python

I want to change colors of image made by specified numbers.
There are three numbers(1, 2 , 3).
By using plt, I could take a image just automatically colored.
However, I want to specify each points(i.e 1 = 'black', 2 = 'yellow', 3 = 'green'). 
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.imshow(subvolume[1,:,:])
ax2.imshow(subvolume2[1,:,:])
plt.show()

A:

You can use a BoundaryNorm with the edges at 0.5, 1.5, ..., and a colormap with the three colors in question. Supply both to imshow(array, cmap=cmap, norm=norm)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors

a = np.random.randint(1,4, size=(5,7))

colors = ['black', 'yellow', 'limegreen']
boundaries = np.arange(1,5)-0.5
cmap = matplotlib.colors.ListedColormap(colors)
norm = matplotlib.colors.BoundaryNorm(boundaries, len(colors))

plt.imshow(a, cmap=cmap, norm=norm)

cb = plt.colorbar(ticks=np.arange(1,4))

plt.show()

This is a special case of the more general Plotting a 2d numpy array with custom colors

