title: matplotlib barplot, generic way of setting the xticklabels in the middle of the bar
body: <p>Following code generates a barplot with the xticklabels centered for each bar. However, scaling the x-axis, changing the number of bars or changing the bar width does alter the position of the labels. Is there a generic way of dealing with that behaviour ?</p>
  
  <pre><code># This code is a hackish way of setting the proper position by trial
  # and error.
  import matplotlib.pyplot as plt
  import numpy as np
  y = [1,2,3,4,5]
  # adding 0.75 did the trick but only if I add a blank position to `xl`
  x = np.arange(0,len(y)) + 0.75
  xl = ['', 'apple', 'orange', 'pear', 'mango', 'peach']
  
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.bar(x,y,0.5)
  ax.set_xticklabels(xl)
  # I cannot change the scaling without changing the position of the tick labels
  ax.set_xlim(0,5.5)
  </code></pre>
  
  <p>The suggested and working solution:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  y = [1,2,3,4,5]
  x = np.arange(len(y))
  xl = ['apple', 'orange', 'pear', 'mango', 'peach'] 
  fig = plt.figure()
  ax = fig.add_subplot(111)
  ax.bar(x,y,0.5, align='center')
  ax.set_xticks(x)
  ax.set_xticklabels(xl)
  </code></pre>