title: Plotting separate Pandas dataframe as barcharts with share x axis
body: <p>I have fallen headlong into this Pandas trap several times in different guises. On this occasion, I want to plot two barcharts, one above the other, using data from two separate dataframes but each plot having a common x axis.</p>
  
  <p>I have two dataframes as follows:</p>
  
  <pre><code>dfA = pd.DataFrame({'year':[2003,2004,2005,2006,2007],
                      'value':[75,84,95,101,119]})
  
  dfA = dfA.set_index('year')
  
  dfB = pd.DataFrame({'year':[2000,2001,2002,2003,2004,2005],
                      'value':[34,46,64,71,88,93]})
  
  dfB = dfB.set_index('year')
  </code></pre>
  
  <p>The dataframes appear as:</p>
  
  <pre><code>      value
  year       
  2003     75
  2004     84
  2005     95
  2006    101
  2007    119
  
        value
  year       
  2000     34
  2001     46
  2002     64
  2003     71
  2004     88
  2005     93
  </code></pre>
  
  <p>I then try to plot the graphs as follows:</p>
  
  <pre><code>fig, axarr = plt.subplots(2,
                            figsize = (4,6),
                            sharex = True)
  
  dfA['value'].plot(kind = 'bar',
                    ax = axarr[0],
                    sharex = True,
                    title = 'DF A')
  
  dfB['value'].plot(kind = 'bar',
                    ax = axarr[1],
                    sharex = True,
                    title = 'DF B')
  
  plt.show()
  </code></pre>
  
  <p>The graphs that are produced show the correct bar heights but the x axes are clearly not shared but instead the bars seem to be plotted one after the other and aligned to the left hand column; the labels used for the x axis are simply the labels from the bottom plot.
  <a href="https://i.stack.imgur.com/PiNGh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PiNGh.png" alt="Bar-plots from different dataframes"></a></p>
  
  <p>One work around it is to outer join both dataframes and then plot each column. (On reflection, this solution is similar to the answer given by #gyx-hh at <a href="https://stackoverflow.com/questions/54327324/plotting-pandas-data-as-an-array-of-bar-chart-does-not-honour-sharex-true">Plotting Pandas data as an array of bar chart does not honour sharex = True</a>.) Outer joining the dataframes works but it works regardless of whether <code>sharex = True</code> is set because the full set of values is present for each dataset even though some cells may contain NaN.</p>
  
  <pre><code>dfC = dfA.join(dfB,
                 how = 'outer',
                 lsuffix = '_A',
                 rsuffix = '_B')
  
        value_A  value_B
  year                  
  2000      NaN     34.0
  2001      NaN     46.0
  2002      NaN     64.0
  2003     75.0     71.0
  2004     84.0     88.0
  2005     95.0     93.0
  2006    101.0      NaN
  2007    119.0      NaN
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cNydE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cNydE.png" alt="Bar-plot with correct x axis"></a></p>
  
  <p>I really like the <code>pandas.plot()</code> method but, for me, this is a very serious glitch that could lead to data being misinterpreted. Should this be raised as a bug with the pandas team or is there a reason why this behaviour is preferable?</p>