title: How do I change the range of the x-axis with datetimes in matplotlib?
body: <p>I'm trying to plot a graph of dates on the x-axis and values on the y-axis. It works fine, except that I can't get the range of the x-axis to be appropriate. The x-axis range is always Jan 2012 to Jan 2016, despite my dates being from today. I am even specifying that xlim should be the first and last date. </p>
  
  <p>I'm writing this for python-django, if that's relevant. </p>
  
  <pre><code> import datetime
   import matplotlib.pyplot as plt
  
   x = [datetime.date(2014, 1, 29), datetime.date(2014, 1, 29), datetime.date(2014, 1, 29)] 
   y = [2, 4, 1]
  
   fig, ax = plt.subplots()
   ax.plot_date(x, y)
   ax.set_xlim([x[0], x[-1]])
  
   canvas = FigureCanvas(plt.figure(1))
   response = HttpResponse(content_type='image/png')
   canvas.print_png(response)
   return response
  </code></pre>
  
  <p>And here is the output:
  <img src="https://i.stack.imgur.com/IlKc3.png" alt="enter image description here"></p>