title: Getting a legend in a seaborn FacetGrid heatmap plot
body: <p>How can we get legends for seaborn <code>FacetGrid</code> heatmaps? The <code>.add_legend()</code> method isn't working for me.</p>
  
  <p>Using code from <a href="https://stackoverflow.com/q/31864770/1461210">this previous question</a>:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import itertools
  import seaborn as sns
  
  print("seaborn version {}".format(sns.__version__))
  # R expand.grid() function in Python
  # https://stackoverflow.com/a/12131385/1135316
  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=['method 1', 'method2', 'method 3', 'method 4']
  times = range(0,100,10)
  data = pd.DataFrame(expandgrid(methods, times, times))
  data.columns = ['method', 'dtsi','rtsi']
  data['nw_score'] = np.random.sample(data.shape[0])
  
  def facet(data,color):
      data = data.pivot(index="dtsi", columns='rtsi', values='nw_score')
      g = sns.heatmap(data, cmap='Blues', cbar=False)
  
  with sns.plotting_context(font_scale=5.5):
      g = sns.FacetGrid(data, col="method", col_wrap=2, size=3, aspect=1)
      g = g.map_dataframe(facet)
      g.add_legend()
      g.set_titles(col_template="{col_name}", fontweight='bold', fontsize=18)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/VAmAp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VAmAp.png" alt="enter image description here"></a></p>