title: skipping empty facets in seaborn facetgrid for annotations
body: <p>I'm working on putting together a <a href="http://web.stanford.edu/%7Emwaskom/software/seaborn/generated/seaborn.FacetGrid.html" rel="nofollow noreferrer">Seaborn facetgrid</a> with data that leaves some grids empty.  Furthermore, I'm annotating each facet with some statistics, however I'm not sure how to &quot;skip&quot; the empty facets so that the annotations fall on the proper facet.</p>
  <p><code>g.axes.flat</code> is of length 9 (9 facets have data); however when I place an annotation on each element in <code>g.axes.flat</code>, it isn't being placed where I expect.</p>
  <pre><code>g = sns.FacetGrid(mapping, col=options.facetCol, row=options.facetRow, col_order=sorted(cols), hue=options.group, sharex=False)
  g = g.map(sns.distplot, options.axis)
  
  # label each facet with stats
  grouped = mapping.groupby([options.facetRow, options.facetCol])
  for ax, (name, df) in zip(g.axes.flat, grouped):
      df2 = df.groupby(options.group) # group by each thing that has its own color and run stats on it
  
      for i, (group, data) in enumerate(df2):
          x = data[options.axis]
  
          # calculate stats and create label
          n = len(x)
          mean = np.mean(x)
          std = np.std(x)
          label = r&quot;%s: n=%s, $\mu$=%.2f $\sigma$=%.2f&quot; %(group, n, mean, std)
          ax.annotate(label, xy=(0.05,0.9-(i*0.05)), xycoords='axes fraction', ha='left', size=8)
  </code></pre>
  <p><img src="https://i.stack.imgur.com/vnSRb.png" alt="enter image description here" /></p>
  <h1>EDIT</h1>
  <p>I've created an annotation function and I'm passing it to the <code>map()</code> [as recommended]; however I'm uncertain how to pass label names to the function and how to get the annotations (there are two for each facet) to shift in the y direction.  Any more suggestions?</p>
  <pre><code>g = g.map(stats, options.axis)
  
  def stats(x, **kwargs):
      ax = sns.distplot(x, **kwargs)
  
      # calculate stats and create label
      n = len(x)
      mean = np.mean(x)
      std = np.std(x)
      label = r&quot;%s: n=%s, $\mu$=%.2f $\sigma$=%.2f&quot; %('moo', n, mean, std) # temporary label, need to pass it through function
      i = 1 # temporary, needs to increment to shift annotations so they aren't on top of each other
  
      # create annotation
      ax.annotate(label, xy=(0.05,0.9-(i*0.05)), xycoords='axes fraction', ha='left', size=8)
  </code></pre>
  <p><img src="https://i.stack.imgur.com/tO54D.png" alt="enter image description here" /></p>