Plotting NaT with matplotlib results in error · Issue #9253 · pandas-dev/pandas (original) (raw)

Trying to plot the NaT (not a time) value of pandas gives an error, where plotting NaN does not.
Expected (and hereby requested) is that NaT is treated just like NaN - i.e., ignore it.

from pylab import * import pandas as pd plot(pd.NaT,5)

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-60addc339c2f> in <module>()
----> 1 plot(pd.NaT,5)

C:\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
   3091         ax.hold(hold)
   3092     try:
-> 3093         ret = ax.plot(*args, **kwargs)
   3094         draw_if_interactive()
   3095     finally:

C:\Anaconda\lib\site-packages\matplotlib\axes\_axes.pyc in plot(self, *args, **kwargs)
   1372 
   1373         for line in self._get_lines(*args, **kwargs):
-> 1374             self.add_line(line)
   1375             lines.append(line)
   1376 

C:\Anaconda\lib\site-packages\matplotlib\axes\_base.pyc in add_line(self, line)
   1484             line.set_clip_path(self.patch)
   1485 
-> 1486         self._update_line_limits(line)
   1487         if not line.get_label():
   1488             line.set_label('_line%d' % len(self.lines))

C:\Anaconda\lib\site-packages\matplotlib\axes\_base.pyc in _update_line_limits(self, line)
   1495         Figures out the data limit of the given line, updating self.dataLim.
   1496         """
-> 1497         path = line.get_path()
   1498         if path.vertices.size == 0:
   1499             return

C:\Anaconda\lib\site-packages\matplotlib\lines.pyc in get_path(self)
    863         """
    864         if self._invalidy or self._invalidx:
--> 865             self.recache()
    866         return self._path
    867 

C:\Anaconda\lib\site-packages\matplotlib\lines.pyc in recache(self, always)
    564                 x = ma.asarray(xconv, np.float_)
    565             else:
--> 566                 x = np.asarray(xconv, np.float_)
    567             x = x.ravel()
    568         else:

C:\Anaconda\lib\site-packages\numpy\core\numeric.pyc in asarray(a, dtype, order)
    460 
    461     """
--> 462     return array(a, dtype, copy=False, order=order)
    463 
    464 def asanyarray(a, dtype=None, order=None):

TypeError: float() argument must be a string or a number

Calling plot with a np.nan results in the point being silently ignored, which I believe should also happen for pd.NaT.

This seems related to #8914, but this example gives an error, where the example of #8914 only results in wrong axes.

This issue was posted in the matplotlib issue tracker as matplotlib/matplotlib#4000, but they believe it can only be fixed in pandas.