title: Changing Date Format X-Axis Matplotlib
body: <p>I have a plot that I need to change the date format along the x-axis to 'YYYY-mm' format. The plot looks like this:</p>
  <p><a href="https://i.stack.imgur.com/YXuTb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YXuTb.png" alt="enter image description here" /></a></p>
  <p>The code looks like this -</p>
  <pre><code>import matplotlib.dates as mdates
  import datetime
  from matplotlib.dates import DateFormatter
  def mean_absolute_percentage_error(y_true, y_pred): 
      y_true, y_pred = np.array(y_true), np.array(y_pred)
      return np.mean(np.abs((y_true - y_pred) / y_true)) * 100
  
  mape = mean_absolute_percentage_error(testarray.monthly_flow, testarray.predicted).round(2) # PRINT MAPE 
  print(mape)
  fpm = (1+mape/100) #'fitted plus mape -- fpm
  fmm = (1-mape/100) #'fitted minus mape -- fmm
  years = mdates.YearLocator()   # every year
  months = mdates.MonthLocator()  # every month
  plus_mape = fitted_series2.multiply(other=fpm)
  minus_mape= fitted_series2.multiply(other=fmm)
  # Plot WITH MAPE +/-
  fig,ax = plt.subplots()
  ax.plot(df2.monthly_flow[-24:])
  ax.plot(fitted_series2[:12], color='darkgreen')
  ax.plot(plus_mape[:12], color='black',linestyle='dotted')
  ax.plot(minus_mape[:12], color='black',linestyle='dotted')
  ax.fill_between(lower_series.index[:12], 
                   lower_series[:12], 
                   upper_series[:12], 
                   color='k', 
                   alpha=.15)
  plt.title(&quot;SARIMAX Forecast of Monthly Col River Flow&quot;)
  plt.show()
  
  date_form = DateFormatter('%YYYY-%mm')
  ax.xaxis.set_major_formatter(date_form)
  plt.show()
  </code></pre>
  <p>And, despite using the 'major_formatter' with the date format specified, it does nothing as you can see with the above plot. I'm not sure what else to do. Thank you for suggestions,</p>