在下面的代码中,bdate和edate都是datetime.datetime()对象:
pylab.barh(ypos, edate - bdate, left=bdate, height=TRMWidth )
Run Code Online (Sandbox Code Playgroud)
但这会在dates.py._to_ordinalf()中抛出AttributeError方式:
文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pyplot.py",第1926行,在barh ret = ax.barh(底部,宽度,高度,左边) ,**kwargs)文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py",第4774行,以barh方向='水平',**kwargs)文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py",第4624行,条形宽度= self.convert_xunits(width)文件"/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py",第147行,在convert_xunits中返回ax.xaxis.convert_units(x)文件"/ Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axis.py",第1312行,在convert_units中ret = self.converter.convert(x,self.units,self)文件"/ Library /Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py",第1125行,在转换中返回date2num(value)在date2num文件中输入文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py",第260行:return np.asarray([_ to_ordinalf(val)for val in d])文件"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py",第189行,在_to_ordinalf base = float(dt.toordinal( ))
AttributeError:'datetime.timedelta'对象没有属性'toordinal'
我认为如果我能在xaxis上推出日期时间并让它解决细节问题会很棒; 没那么多.有关如何使日期与xaxis相关的任何建议?