title: Plot multiple bars for categorical data
body: <p>I'm looking for a way to plot multiple bars per value in matplotlib. For numerical data, this can be achieved be adding an offset to the X data, as described for example <a href="https://stackoverflow.com/q/14270391/2969841">here</a>:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  X = np.array([1,3,5])
  Y = [1,2,3]
  Z = [2,3,4]
  
  plt.bar(X - 0.4, Y) # offset of -0.4
  plt.bar(X + 0.4, Z) # offset of  0.4
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WoTrc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/WoTrc.png" alt="Multiple bars for numerical data"></a></p>
  
  <p><code>plt.bar()</code> (and <code>ax.bar()</code>) also handle categorical data automatically:</p>
  
  <pre><code>X = ['A','B','C']
  Y = [1,2,3]
  
  plt.bar(X, Y)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/huKwR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/huKwR.png" alt="Category handling"></a></p>
  
  <p>Here, it is obviously not possible to add an offset, as the categories are not directly associated with a value on the axis. I can manually assign numerical values to the categories and set labels on the x axis with <code>plt.xticks()</code>:, </p>
  
  <pre><code>X = ['A','B','C']
  Y = [1,2,3]
  Z = [2,3,4]
  _X = np.arange(len(X))
  
  plt.bar(_X - 0.2, Y, 0.4)
  plt.bar(_X + 0.2, Z, 0.4)
  plt.xticks(_X, X) # set labels manually
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/jV9pe.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jV9pe.png" alt="Manually setting category labels"></a></p>
  
  <p>However, I'm wondering if there is a more elegant way that makes use of the automatic category handling of <code>bar()</code>, especially if the number of categories and bars per category is not known in before (this causes some fiddling with the bar widths to avoid overlaps).</p>