You can directly modify the colors of the grid created by pcolormesh
. For example:
import numpy as np
import matplotlib.pyplot as plt
nrows = 10
ncols = 10
a = np.random.rand(nrows, ncols)
pcm = plt.pcolormesh(a, cmap="Greys")
# Apparently need to render once in order to assign facecolors
# to the grid created by pcolormesh:
plt.draw()
fc = pcm.get_facecolors()
fc_grid = fc.reshape(nrows, ncols, -1)
alpha = 0.2
fc_grid[:, 3:6] = (1-alpha)*fc_grid[:, 3:6] + alpha*np.array([1.0, 0, 0, 1])
fc_grid[4:7, 7:] = (1-alpha)*fc_grid[4:7, 7:] + alpha*np.array([0, 1.0, 0, 1])
plt.show()
Here's the PNG version of the plot it creates:
If you save it as EPS, the colors are correct.