title: Python Seaborn heatmap annotations after masking
body: <p>I am creating a Seaborn heatmap with a given pandas dataframe that has numbers and nan's. Something like so:</p>
  
  <pre><code>1 2 nan
  4 nan nan
  nan nan nan
  </code></pre>
  
  <p>I need the heatmap to be annoted and I also need to mask/grey out all the nans. I found the mask function and can use it like so:</p>
  
  <pre><code>mask = df.isnull()
  </code></pre>
  
  <p>Then, I can create the heatmap like so:</p>
  
  <pre><code>sns.heatmap(df, mask = mask, annot = True, fmt = "g", cmap = "Blues")
  </code></pre>
  
  <p>The problem is, with the mask, it seems the nan's are transformed into strings while the numbers stay as floats. I get the following exception:</p>
  
  <blockquote>
    <p>ValueError: Unknown format code 'g' for object of type 'str'</p>
  </blockquote>
  
  <p>With something like this happening (partial plot before it throws the exception):</p>
  
  <p><img src="https://i.stack.imgur.com/qOtem.png" alt="enter image description here"></p>
  
  <p>As you can tell, the first cell formatted is fine as it's a float, but then, when it gets to the nan that is masked, it seems it is not a string and cannot be formatted.</p>
  
  <p>Does anyone have any suggestions on how to annotate only the unmasked data?</p>
  
  <p>Thanks</p>