title: Python matplotlib.dates.date2num: converting numpy array to matplotlib datetimes
body: <p>I am trying to plot a custom chart with datetime axis. My understanding is that matplotlib requires a float format which is days since epoch. So, I want to convert a numpy array to the float epoch as required by matplotlib.</p>
  
  <p>The datetime values are stored in a numpy array called t:</p>
  
  <pre><code>In [235]: t
  Out[235]: array(['2008-12-01T00:00:59.000000000-0800',
                   '2008-12-01T00:00:59.000000000-0800',
                   '2008-12-01T00:00:59.000000000-0800',
                   '2008-12-01T00:09:26.000000000-0800',
                   '2008-12-01T00:09:41.000000000-0800'], dtype='datetime64[ns]')
  </code></pre>
  
  <p>Apparently, matplotlib.dates.date2num only accepts a sequence of python datetimes as input (not numpy datetimes arrays):</p>
  
  <pre><code>import matplotlib.dates as dates
  plt_dates = dates.date2num(t)
  </code></pre>
  
  <p>raises AttributeError: 'numpy.datetime64' object has no attribute 'toordinal'</p>
  
  <p>How should I resolve this issue? I hope to have a solution that works for all types of numpy.datetime like object. </p>
  
  <p>My best workaround (which I am not sure to be correct) is not to use date2num at all. Instead, I try to use the following:</p>
  
  <pre><code>z = np.array([0]).astype(t.dtype)
  plt_dates = (t - z)/ np.timedelta64(1,'D')
  </code></pre>
  
  <p>Even, if this solution is correct, it is nicer to use library functions, instead of manual adhoc workarounds.</p>