title: Matplotlib DateFormatter for axis label not working
body: <p>I'm trying to adjust the formatting of the date tick labels of the x-axis so that it only shows the Year and Month values. From what I've found online, I have to use <code>mdates.DateFormatter</code>, but it's not taking effect at all with my current code as is. Anyone see where the issue is? (the dates are the index of the pandas Dataframe)</p>
  
  <pre><code>import matplotlib.dates as mdates
  import matplotlib.pyplot as plt
  import pandas as pd 
  
  fig = plt.figure(figsize = (10,6))
  ax = fig.add_subplot(111)
  
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
  
  basicDF['some_column'].plot(ax=ax, kind='bar', rot=75)
  
  ax.xaxis_date()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/i3otd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/i3otd.png" alt="enter image description here"></a></p>
  
  <p><strong>Reproducible scenario code:</strong></p>
  
  <pre><code>import numpy as np
  import matplotlib.dates as mdates
  import matplotlib.pyplot as plt
  import pandas as pd 
  
  rng = pd.date_range('1/1/2014', periods=20, freq='m')
  
  blah = pd.DataFrame(data = np.random.randn(len(rng)), index=rng)
  
  fig = plt.figure(figsize = (10,6))
  ax = fig.add_subplot(111)
  
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
  
  blah.plot(ax=ax, kind='bar')
  
  ax.xaxis_date()
  </code></pre>
  
  <p>Still can't get just the year and month to show up.</p>
  
  <p>If I set the format after .plot , get an error like this:</p>
  
  <blockquote>
    <p>ValueError: DateFormatter found a value of x=0, which is an illegal date. This usually occurs because you have not informed the axis that it is plotting dates, e.g., with a<code>x.xaxis_date()</code>. </p>
  </blockquote>
  
  <p>It's the same for if I put it before ax.xaxis_date() or after.</p>