I plot a dataframe in a heatmap-like plot, and I would like to write to the cell, but not the value of the cell but I compare the value with conditions and tells which kind of error it is.
For example:
import pandas as pd
import seaborn as sns # matplotlib inline
import random
data = []
for i in range(10):
data.append([random.randrange(0, 11, 1) for _ in range(10)])
df = pd.DataFrame(data)
n = 10
fig, ax = plt.subplots(figsize = (12, 10))
cmap = ['#b3e6b3','#66cc66','#2d862d','#ffc299','#ff944d','#ff6600','#ccddff','#99bbff','#4d88ff','#0044cc','#002b80']
ax = sns.heatmap(df, cmap=cmap, linewidths = 0.005, annot = False)
plt.show()
What I got when running this code is:
Then I compare dataframe df with some conditions and get 2 other dataframes, for example:
condition1 = [['Error A'] + [np.nan]*9,
[np.nan]*6 + ['Error C'] + [np.nan]*3,
[np.nan]*10,
[np.nan]*7 + ['Error B'] + [np.nan]*2,
[np.nan]*2 + ['Error D'] + [np.nan]*3 + ['Error B'] + [np.nan]*3,
[np.nan]*10,
[np.nan]*3 + ['Error B'] + [np.nan]*6,
[np.nan]*7 + ['Error A'] + [np.nan]*2,
[np.nan]*10,
[np.nan]*10]
df_condition1 = pd.DataFrame(data = condition1)
condition2 = [[np.nan]*10,[np.nan]*10,
[np.nan]*10,[np.nan]*7 + ['Error C'] + [np.nan]*2,
[np.nan]*10,[np.nan]*10,[np.nan]*10,
[np.nan]*10,
[np.nan]*10,
[np.nan]*10]
df_condition2 = pd.DataFrame(data = condition2)
and what I want is to show values of these dataframes in the heatmap, like this:
How can I do it?


