## Fix Python – matplotlib: colorbars and its text labels

I’d like to create a colorbar legend for a heatmap, such that the labels are in the center of each discrete color. Example borrowed from here:

import matplotlib.pyplot as plt

import numpy as np

from matplotlib.colors import ListedColormap

#discrete color scheme

cMap = ListedColormap([‘white’, ‘green’, ‘blue’,’red’])

#data

np.random.seed(42)

data….