Shifting x labels in Matplotlib, Ipython
<p>I'm trying to make three charts in one output with matplotlib in an ipython notebook. When I output the chart is correct for the fisrt one, but on the second and third the x labels are messed up, and there are more cells in the second and third chart. I want them all to be uniform. </p>

<pre><code>fig, axs = plt.subplots(1,3, figsize=(15,10))
ax0, ax1, ax2 = axs.flat

labels = ['Asian', 'Black', 'Hispanic', 'Unknown', 'White']

day1M = day1df[(day1df.Gender == "M")]
day15M = day15df[(day15df.Gender == "M")]
day30M = day30df[(day30df.Gender == "M")]


grouped1 = day1M.groupby("Race").size()
grouped15 = day15M.groupby("Race").size()
grouped30= day30M.groupby("Race").size()

x = range(len(grouped1))

ax0.bar(x, grouped1)
ax0.set_xticklabels(labels, rotation='vertical')


x = range(len(grouped15))

ax1.bar(x, grouped15)
ax1.set_xticklabels(labels, rotation='vertical')

x = range(len(grouped30))

ax2.bar(x, grouped30)
ax2.set_xticklabels(labels, rotation='vertical')
</code></pre>

<p>and here is what the current output looks like</p>

<p><a href="http://i.stack.imgur.com/JpYnO.png" rel="nofollow"><img src="http://i.stack.imgur.com/JpYnO.png" alt="Chart1"></a></p>

<p>You should almost never use <code>set_xticklabels</code> because it is (under the hood) just using a <code>FixedFormatter</code> to tick labels.  If you do not also set the locator to be <code>FixedLocator</code>, then the tick labels are applied, in sequence, to the ticks.</p>

<p>As of mpl 1.5, there is a <code>tick_label</code> kwarg to <code>bar</code> <a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.bar" rel="nofollow">(docs)</a> that will automatically label your bars.  I suspect you want to do something like</p>

<pre><code>ax.bar(x, data, tick_label=labels, align='center')
</code></pre>

python pandas matplotlib ipython