title: Custom X-Axis Date Range Using Matplotlib
body: <p>This is my first time asking a Python question online.  I have always been able to find answers to my questions on this site..until now.  I am trying to plot data that were developed using the Index Sequential Method, which is a technique for projecting historical data into the future.  I have 105 charts that each cover 47 years of data.  The first chart x-axis ranges from 1906-1952, the second 1907-1953, thir 1908-1954, etc.  My problem is when I get to 1963, which is when the 47th year reverts back to the begining (1906).  So the 1963 chart xaxis would look like this: 1963, 1964, 1965,...2008,2009,2010,1906.  The 1964 chart xaxis would look like this: 1964, 1965, 1967,...2009, 2010, 1906, 1907.</p>
  
  <p>I can get the data to plot fine, I just need help figuring out how to format the xaxis to accept the unique wrap-around situation when it occurs.</p>
  
  <p>There are three charts per page (ax1, ax2, and ax3).  yearList and chartList are the x and y data, respectively.  The code below is part of a for loop that creates the yearList and chartList data sets, and it creates the charts with the wrong xaxis labels.</p>
  
  <pre><code>import matplotlib, pyPdf
  import matplotlib.pyplot as plt
  import matplotlib.dates as mdates
  import matplotlib.ticker as tkr
  from matplotlib.ticker import MultipleLocator
  import matplotlib.figure as figure
  
  plt.rcParams['font.family'] = 'Times New Roman'
  locator = mdates.YearLocator(2)
  minorLocator = MultipleLocator(1)
  dateFmt = mdates.DateFormatter('%Y')
  datemin = min(yearList)
  datemax = max(yearList)
  
  fig, (ax1, ax2, ax3) = plt.subplots(3,1,sharex=False)
  #3X3 Top to bottom
  ax1.bar(yearList1, chartList1, width=200, align='center')
  ax2.bar(yearList2, chartList2, width=200, align='center')
  ax3.bar(yearList3, chartList3, width=200, align='center')
  
  axList = [ax1, ax2, ax3]
  
  for ax in axList:
      ax.xaxis.set_major_locator(locator)
      ax.xaxis.set_major_formatter(dateFmt)
      ax.xaxis.set_minor_locator(minorLocator)
      ax.set_xlim(datemin - timedelta(365), datemax + timedelta(365))
      ax.grid(1)
      ax.set_ylim(0,30)
      ax.set_yticks(np.arange(0, 31, 5))
      ax.yaxis.set_minor_locator(minorLocator)
      #Rotate tick labels 90 degrees
      xlabels = ax.get_xticklabels()
          for label in xlabels:
              label.set_rotation(90)
          fig.tight_layout()
  
   plt.subplots_adjust(right=0.925)
   plt.savefig('%s\\run.pdf' % outDir)
  </code></pre>