title: How to Annotate sublots of heatmaps in matplotlip
body: <p>I am plotting a heatmap in matplotlib using custom defined function and would like to add annotation for 
  each box in grid. basically each grid should show 3,4's annotated. I think the solution is not trivial so I have done some research before asking here</p>
  
  <p>By following the instructions from these posts
  <a href="https://github.com/matplotlib/matplotlib/issues/10956" rel="nofollow noreferrer">https://github.com/matplotlib/matplotlib/issues/10956</a>
  <a href="https://stackoverflow.com/questions/11917547/how-to-annotate-heatmap-with-text-in-matplotlib/11918066">how to annotate heatmap with text in matplotlib?</a>
  <a href="https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/image_annotated_heatmap.html" rel="nofollow noreferrer">https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/image_annotated_heatmap.html</a></p>
  
  <p>I tried to solve the problem but it seems that I'm missing something.</p>
  
  <p>Then I added a for loop under <code>facet</code> function below but it does not output desired plot and throwing a KeyError: (0,0)</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import itertools
  import seaborn as sns
  from matplotlib.colors import ListedColormap
  import matplotlib.pyplot as plt
  
  def expandgrid(*itrs):
     product = list(itertools.product(*itrs))
     return {'Var{}'.format(i+1):[x[i] for x in product] for i in range(len(itrs))}
  
  methods=["m" + str(i) for i in range(1,3)]
  labels=["l" + str(i) for i in range(1,4)]
  
  times = range(0,100,25)
  data = pd.DataFrame(expandgrid(methods,labels, times, times))
  data.columns = ['method','labels','dtsi','rtsi']
  #data['nw_score'] = np.random.sample(data.shape[0])
  data['nw_score'] = np.random.choice([3,4],data.shape[0])
  
  data.head()
  
  method labels  dtsi  rtsi  nw_score
  0     m1     l1     0     0         4
  1     m1     l1     0    25         4
  2     m1     l1     0    50         4
  3     m1     l1     0    75         3
  4     m1     l1    25     0         3
  
  cmap=ListedColormap(['red', 'blue'])
  
  def facet(data, ax):
      data = data.pivot(index="dtsi", columns='rtsi', values='nw_score')
      ax.imshow(data, cmap=cmap,extent=[0,100,0,100])
      for i in range(data.shape[0]):
          for j in range(data.shape[1]):
              ax.text(j, i, "{:.2f}".format(data[i,j]), ha="center", va="center")
  
  
  
  def myfacetgrid(data, row, col, figure=None):
      rows = np.unique(data[row].values)  
      cols = np.unique(data[col].values)
  
      fig, axs = plt.subplots(3, 2, 
                              figsize=(2*len(cols)+1, 2*len(rows)+1))
  
      for i, r in enumerate(rows):
          row_data = data[data[row] == r]
          for j, c in enumerate(cols):
              this_data = row_data[row_data[col] == c]
              facet(this_data, axs[i,j])
      return fig, axs
  
  with sns.plotting_context(font_scale=5.5):
      fig, axs = myfacetgrid(data, row="labels", col="method")
  
  
      for ax,method in zip(axs[0,:],data.method.unique()):
          ax.set_title(method, fontweight='bold', fontsize=12)
      for ax,label in zip(axs[:,0],data.labels.unique()):
          ax.set_ylabel(label, fontweight='bold', fontsize=12, rotation=0, ha='right', va='center')
          #fig.suptitle(lt, fontweight='bold', fontsize=12)
      fig.tight_layout()
      fig.subplots_adjust(top=0.8) # make some room for the title
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/ta65j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ta65j.png" alt="enter image description here"></a></p>
  
  <p>After adding for loop to <code>facet</code> function it seems that everything fall aparts.</p>