title: Annotate Percentage of Group within a Seaborn CountPlot
body: <p>The below code gets the percentage of all collisions. However, I want to get the percentage within a group. E.G. Mid-Block (not related to intersection) has 2 labels, a 1(red) or a 2(green/blue). Currently, the percentages next to those bars are percentages of the whole (bar count / all collisions), but I need to display the percentage within just one y-axis label. E.G. for Mid-block (not related to intersection), bar count / all collisions within mid-block (not related to intersection). I do not know how to do this, so if someone could point me in the right direction or give me some code that I could study to understand, I'd be very grateful.</p>
  <p>Thank you so much for your time.</p>
  <pre><code>plt.style.use('ggplot')
  plt.figure(figsize = (20, 15))
  ax = sb.countplot(y = &quot;JUNCTIONTYPE&quot;, hue = &quot;SEVERITYCODE&quot;, data = dfm)
  plt.title('Number of Persons vs. Number of Collisions by Severity', fontsize = 30)
  plt.xlabel('Number of Collisions', fontsize = 24)
  plt.ylabel('Number of Persons', fontsize = 24)
  plt.tick_params(labelsize=18);
  plt.legend(fontsize = 18, title = &quot;Severity&quot;, loc = 'lower right')
  plt.text(5, 6, &quot;Figure 8: Number of persons plotted against the number of collisions grouped by severity&quot;, fontsize = 16)
  # labels = [item.get_text() for item in ax.get_yticklabels()]
  # labels[0] = 'No'
  # labels[1] = 'Yes'
  # ax.set_yticklabels(labels)
  
  for p in ax.patches:
      width = p.get_width()
      height = p.get_height()
      x, y = p.get_xy()
      ax.annotate(int(width),
                  ((x + width), y), 
                  xytext = (30, -25),
                  fontsize = 18, 
                  color = '#000000',
                  textcoords = 'offset points',
                  ha = 'right',
                  va = 'center')
      
  for p in ax.patches:
      width = p.get_width()
      height = p.get_height()
      x, y = p.get_xy()
      totals = []
      for i in ax.patches:
          totals.append(i.get_width())
      total = sum(totals)
      ax.text(width + 0.3, y + 0.38, 
              str(
                  round((width/total) * 100, 2)) 
                  + '%',
              fontsize=18)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/kIw68.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kIw68.png" alt="enter image description here" /></a></p>