title: NameError: name 'dates' is not defined
body: <p>I am getting an error "NameError: name 'dates' is not defined" when I'm trying to call dates.MonthLocator() </p>
  
  <pre><code>import pandas as pd
  import matplotlib.pyplot as plt
  
  df1 = pd.read_csv('tcs.csv', index_col = 'Date', parse_dates = True)
  
  idx = df1.loc['2019-01-01':'2019-02-01'].index
  stk = df1.loc['2019-01-01':'2019-02-01']['Close Price']
  
  fig,ax =plt.subplots()
  ax.plot_date(idx,stk,'-')
  
  # ax.xaxis.grid(True)
  # ax.yaxis.grid(True)
  
  ax.xaxis.set_major_locator(dates.MonthLocator())
  ax.xaxis.set_major_formatter(dates.DateFormatter("%b-%y"))
  
  fig.autofmt_xdate()
  plt.tight_layout()
  </code></pre>
  
  <p>and I am getting a Name error.</p>
  
  <pre><code>NameError                                 Traceback (most recent call last)
  &lt;ipython-input-6-32ecec70e866&gt; in &lt;module&gt;
       13 # ax.yaxis.grid(True)
       14 
  ---&gt; 15 ax.xaxis.set_major_locator(dates.MonthLocator())
       16 ax.xaxis.set_major_formatter(dates.DateFormatter("%b-%y"))
       17 
  
  NameError: name 'dates' is not defined
  </code></pre>
  
  <p>Here is how df1 looks like.</p>
  
  <p><a href="https://i.stack.imgur.com/0TDUJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0TDUJ.png" alt="Screenshot"></a></p>
  
  <p>Please let me know why I'm getting this error</p>