title: Custom Annotation Seaborn Heatmap
body: <p>I'm using Seaborn in Python to create a Heatmap. I'm able to annotate the cells with the values passed in, but I'd like to add annotations that signify what the cell means. For example, instead of merely seeing <code>0.000000</code>, I'd like to see the corresponding label, for instance "Foo," or <code>0.000000 (Foo)</code>.</p>
  
  <p>The <a href="http://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.heatmap.html#seaborn.heatmap">Seaborn documentation</a> for the heatmap function is a bit cryptic with the parameter that I believe is the key here:</p>
  
  <pre><code>annot_kws : dict of key, value mappings, optional
    Keyword arguments for ax.text when annot is True.
  </code></pre>
  
  <p>I tried setting <code>annot_kws</code> to a dictionary of the aliases to the values, i.e., <code>{'Foo' : -0.231049060187, 'Bar' : 0.000000}</code>, etc., but I'm getting an AttributeError.</p>
  
  <p>Here is my code (I've manually created the data array here for reproducability):</p>
  
  <pre><code>data = np.array([[0.000000,0.000000],[-0.231049,0.000000],[-0.231049,0.000000]])
  axs = sns.heatmap(data, vmin=-0.231049, vmax=0, annot=True, fmt='f', linewidths=0.25)
  </code></pre>
  
  <p>Here is the (working) output when I don't use the <code>annot_kws</code> parameter:</p>
  
  <p><a href="https://i.stack.imgur.com/j11LR.png"><img src="https://i.stack.imgur.com/j11LR.png" alt="Working output"></a></p>
  
  <p>And here the stack trace for when I <em>do</em> include the <code>annot_kws</code> param:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-57-38f91f1bb4b8&gt; in &lt;module&gt;()
       12 
       13 
  ---&gt; 14 axs = sns.heatmap(data, vmin=min(uv), vmax=max(uv), annot=True, annot_kws=kws, linewidths=0.25)
       15 concepts
  
  /opt/anaconda/2.3.0/lib/python2.7/site-packages/seaborn/matrix.pyc in heatmap(data, vmin, vmax, cmap, center, robust, annot, fmt, annot_kws, linewidths, linecolor, cbar, cbar_kws, cbar_ax, square, ax, xticklabels, yticklabels, mask, **kwargs)
      272     if square:
      273         ax.set_aspect("equal")
  --&gt; 274     plotter.plot(ax, cbar_ax, kwargs)
      275     return ax
      276 
  
  /opt/anaconda/2.3.0/lib/python2.7/site-packages/seaborn/matrix.pyc in plot(self, ax, cax, kws)
      170         # Annotate the cells with the formatted values
      171         if self.annot:
  --&gt; 172             self._annotate_heatmap(ax, mesh)
      173 
      174         # Possibly add a colorbar
  
  /opt/anaconda/2.3.0/lib/python2.7/site-packages/seaborn/matrix.pyc in _annotate_heatmap(self, ax, mesh)
      138             val = ("{:" + self.fmt + "}").format(val)
      139             ax.text(x, y, val, color=text_color,
  --&gt; 140                     ha="center", va="center", **self.annot_kws)
      141 
      142     def plot(self, ax, cax, kws):
  
  /opt/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in text(self, x, y, s, fontdict, withdash, **kwargs)
      590         if fontdict is not None:
      591             t.update(fontdict)
  --&gt; 592         t.update(kwargs)
      593         self.texts.append(t)
      594         t._remove_method = lambda h: self.texts.remove(h)
  
  /opt/anaconda/2.3.0/lib/python2.7/site-packages/matplotlib/artist.pyc in update(self, props)
      755             func = getattr(self, 'set_' + k, None)
      756             if func is None or not six.callable(func):
  --&gt; 757                 raise AttributeError('Unknown property %s' % k)
      758             func(v)
      759             changed = True
  
  AttributeError: Unknown property tokenized
  </code></pre>
  
  <p>Finally, <code>kws</code>, the attribute I'm passing in the line in the stack trace, is the dictionary and it would look basically like this:</p>
  
  <pre><code>kws = {'Foo': -0.231049060187, 'Bar': 0.0}
  </code></pre>
  
  <p>Hope everything makes sense, and I'd appreciate any help anyone can give.</p>