title: Python Matplotlib – Bar chart on their representing sampling position on x-axis
body: <p>I want to plot sampling data of different groups in a stacked bar chart. The sampling was performed at different km. The distance between each sampling point is not equal. Normally, when plotting with matplotlib.pyplot.bar or pandas.DataFrame.plot.bar, the bars are plotted one behind the other. Their km-value isn't represented on the x-axis. How I can plot stacked bar plots at their representing km-position on the x-axis?</p>
  
  <p>Code of a standard bar plot with <code>pandas.DataFrame.plot.bar</code>:</p>
  
  <pre><code>import pandas as pd
  import matplotlib.pyplot as plt
  
  df = pd.DataFrame( {'Group 1': {-60.0:0, -20.0:0, 12.5:0, 62.0:0, 123.8:0, 181.0: 5.013532366071429e-06, 225.2: 0.00010224713604266826, 248.0: 0.0002520240051269531, 274.9: 0.0006304542296807856, 304.2: 0.0009587457616051962, 331.0: 0.0021422429744175505}, 'Group 2': {-60.0: 0.0003144776457026891, -20.0: 5.43150903588747e-05, 12.5: 0.00012757662141348495, 62.0: 6.852403753623154e-05, 123.8: 5.980538377849872e-05, 181.0: 5.000001780657088e-05, 225.2: 0.00010152032391840468, 248.0: 0.0005436288535458056, 274.9: 0.00038244130009346957, 304.2: 0.00023423789360943164, 331.0: 9.508221455006986e-05}, 'Group 3': {-60.0: 0.00021804919790451726, -20.0: 0.0002884471518114942, 12.5: 0.00024001954291413006, 62.0: 0.00020780311751064946, 123.8:0, 181.0: 0.0003548555407567293, 225.2: 0.0011448858440205976, 248.0: 0.0031436022397010425, 274.9: 0.001858462242669843, 304.2: 0.0019485330483867962, 331.0: 0.0017062062250634059}} )
  ax = df.plot.bar(stacked=True)
  ax.set_ylabel('TM [mg/l]')
  ax.set_xlabel('km')
  plt.tight_layout()
  </code></pre>
  
  <p>For clearance:</p>
  
  <p>Standard bar plot
  <img src="https://i.stack.imgur.com/jVzuW.png" alt="enter image description here"></p>
  
  <p>What I want
  <img src="https://i.stack.imgur.com/0hwAi.png" alt="enter image description here"></p>