title: Pandas auto datetime format in matplotlib
body: <p>I frequently plot multiple timeseries data from different sources on a single plot, some of which require using matplotlib. When formatting the x-axis, I use matplotlib's <code>autofmt_xdate()</code>, but I much prefer the auto formatting of pandas. I'm aware I can manually set the format using <code>set_major_formatter()</code>, but the plots I create vary from years, to days in total range, so I would need to adjust the formatting based on each plot. Is there a way to set matplotlib to auto format the x-axis with dates similar to pandas?</p>
  
  <p>I also use interactive plotting, and when using pandas <code>df.plot()</code> the x-axis updates when zooming to the respective ranges as shown below, which I would also like to achieve using matplotlib:</p>
  
  <p><a href="https://i.stack.imgur.com/DOKk6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DOKk6.png" alt="pandas format month "></a>
  <a href="https://i.stack.imgur.com/YsnDF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YsnDF.png" alt="pandas format day"></a>
  <a href="https://i.stack.imgur.com/u1xOw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u1xOw.png" alt="pandas format inter-day"></a></p>
  
  <p>Versions:</p>
  
  <pre><code>Python: 3.7.1
  Pandas: 0.23.3
  Matplotlib: 2.2.2
  </code></pre>
  
  <p><strong>Desired Format:</strong></p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  
  ix = pd.date_range('1/1/2017', '11/1/2018', freq='D')
  vals = np.random.randn(len(ix))
  df = pd.DataFrame({'Values': vals}, index=ix)
  
  fig, ax = plt.subplots(1, 1, figsize=[8,6])
  df.plot(ax=ax, lw=1)
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/2jALF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2jALF.png" alt="desired pandas format"></a></p>
  
  <p><strong>Current Format:</strong></p>
  
  <pre><code>fig, ax = plt.subplots(1, 1, figsize=[8,6])
  ax.plot(df, lw=1)
  fig.autofmt_xdate()
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/piOi7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/piOi7.png" alt="Current matplotlib format"></a></p>