title: Seaborn: countplot() with frequencies
body: <p>I have a Pandas DataFrame with a column called "AXLES", which can take an integer value between 3-12. I am trying to use Seaborn's countplot() option to achieve the following plot:</p>
  
  <ol>
  <li>left y axis shows the frequencies of these values occurring in the data. The axis extends are [0%-100%], tick marks at every 10%.</li>
  <li>right y axis shows the actual counts, values correspond to tick marks determined by the left y axis (marked at every 10%.)</li>
  <li>x axis shows the categories for the bar plots [3, 4, 5, 6, 7, 8, 9, 10, 11, 12].</li>
  <li>Annotation on top of the bars show the actual percentage of that category.</li>
  </ol>
  
  <p>The following code gives me the plot below, with actual counts, but I could not find a way to convert them into frequencies. I can get the frequencies using <code>df.AXLES.value_counts()/len(df.index)</code> but I am not sure about how to plug this information into Seaborn's <code>countplot()</code>.</p>
  
  <p>I also found a workaround for the annotations, but I am not sure if that is the best implementation.</p>
  
  <p>Any help would be appreciated!</p>
  
  <p>Thanks</p>
  
  <pre><code>plt.figure(figsize=(12,8))
  ax = sns.countplot(x="AXLES", data=dfWIM, order=[3,4,5,6,7,8,9,10,11,12])
  plt.title('Distribution of Truck Configurations')
  plt.xlabel('Number of Axles')
  plt.ylabel('Frequency [%]')
  
  for p in ax.patches:
          ax.annotate('%{:.1f}'.format(p.get_height()), (p.get_x()+0.1, p.get_height()+50))
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/4CyuQ.png"><img src="https://i.stack.imgur.com/4CyuQ.png" alt="enter image description here"></a></p>
  
  <h3>EDIT:</h3>
  
  <p>I got closer to what I need with the following code, using Pandas' bar plot, ditching Seaborn. Feels like I'm using so many workarounds, and there has to be an easier way to do it. The issues with this approach:</p>
  
  <ul>
  <li>There is no <code>order</code> keyword in Pandas' bar plot function as Seaborn's countplot() has, so I cannot plot all categories from 3-12 as I did in the countplot(). I need to have them shown even if there is no data in that category.</li>
  <li><p>The secondary y-axis messes up the bars and the annotation for some reason (see the white gridlines drawn over the text and bars).</p>
  
  <pre><code>plt.figure(figsize=(12,8))
  plt.title('Distribution of Truck Configurations')
  plt.xlabel('Number of Axles')
  plt.ylabel('Frequency [%]')
  
  ax = (dfWIM.AXLES.value_counts()/len(df)*100).sort_index().plot(kind="bar", rot=0)
  ax.set_yticks(np.arange(0, 110, 10))
  
  ax2 = ax.twinx()
  ax2.set_yticks(np.arange(0, 110, 10)*len(df)/100)
  
  for p in ax.patches:
      ax.annotate('{:.2f}%'.format(p.get_height()), (p.get_x()+0.15, p.get_height()+1))
  </code></pre></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/lqe7r.png"><img src="https://i.stack.imgur.com/lqe7r.png" alt="enter image description here"></a></p>