title: How to align annotations at the end of a horizontal bar plot
body: <p>I'm trying to correctly align the numbers and percentages in the barplots I'm making so that they're exactly after each bar, but having some troubles trying to do so. I want the: &quot;number (%percentage)&quot; to come exactly after each bar (very small space between). However, now in case of the upper ones (Top 200, 400) the number and percentage are already shifted more forwards than the bottom ones (Top1-50). So when I try to shift them the bottom ones lack behind the upper ones, resulting in not very aesthetically pleasing look. Is there a way to fix this?</p>
  <pre class="lang-py prettyprint-override"><code>import matplotlib
  import matplotlib.pyplot as plt
  import numpy as np
  plt.rcParams.update(plt.rcParamsDefault)
  
  labels = [&quot;Top1&quot;, &quot;Top3&quot;, &quot;Top5&quot;, &quot;Top10&quot;, &quot;Top20&quot;, &quot;Top50&quot;, &quot;Top100&quot;, &quot;Top200&quot;, &quot;Top400&quot;]
  native_shape_1000=[38, 42, 44, 48, 52, 57, 61, 66, 68] #Native pose (restr. to shapes &amp; it0 1000)
  native_pocket_1000=[43, 51, 51,57,60,64,67,68,69] #Native pose (restr. to pocket residues)
  
  x = np.arange(len(native_shape_1000))  # the label locations
  width = 0.4  
  fig, axes = plt.subplots(2,2, figsize=(12,8), sharey= False, sharex=False)
  axes= axes.flatten()
  rects1=axes[0].barh(x - width/2, native_shape_1000, width, label=' Restraints to rank 1 \n pocket shapes;\n it0 = 1000')
  rects2=axes[0].barh(x + width/2, native_pocket_1000, width, label=' Restraints to rank 1 \n pocket residues;\n it0 = 1000')
  
  axes[0].set_xlim(xmin=0, xmax=102)
  axes[0].set_xticks([x for x in range(0,103,10)])
  axes[0].set_yticks(x)
  axes[0].set_yticklabels(labels)
  axes[0].legend(loc=4, prop={'size': 8})
  
  
  def autolabel(rects, axes):
  
      for rect in rects:
          width = rect.get_width()
          perc=int(round(width/102*100))
          axes.annotate(f'{width} ({perc}%) ',
                        xy=(width, rect.get_y()+ rect.get_height()), 
                        xytext=(0,0),
                        textcoords=&quot;offset points&quot;,
                        ha='left', va='bottom')
  
  autolabel(rects1, axes[0])
  # autolabel(rects2)
  # autolabel rects3,4 etc.
  # fig.tight_layout()
  
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/hJykA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hJykA.png" alt="enter image description here" /></a></p>