Python ProgrammingPython Programming

Distinguish NA cells from the other cells in HeatMap

Hatch the background axes patch

import matplotlib.pyplot as plt
import matplotlib.patches as patches

import numpy as np

column_labels = list('ABCDEFGH')
row_labels = list('12345678')

data = np.random.rand(8, 8)
data =, 0.8)

fig, ax = plt.subplots()
heatmap = ax.pcolor(data,, edgecolors='blue', linewidths=1,

ax.patch.set(hatch='..', edgecolor='red')

# Put the major ticks at the middle of each cell
ax.set_xticks(np.arange(data.shape[0]), minor=False)
ax.set_yticks(np.arange(data.shape[0]), minor=False)

# Want a more natural, table-like display

ax.set_xticklabels(row_labels, minor=False)
ax.set_yticklabels(column_labels, minor=False)

The following is the output that will be obtained:

Distinguish NA cells from the other cells in HeatMap in Matplotlib