在下面的代码中, bdate 和 edate 都是 datetime.datetime() 对象:
pylab.barh(ypos, edate - bdate, left=bdate, height=TRMWidth )
但这会在 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(bottom, width, height, left , **kwargs) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/axes.py”,第 4774 行,barhorientation='horizontal',** 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) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”,第 260 行, 在 date2num 中 else: return np.asarray([_to_ordinalf(val) for val in d]) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates. py",第 189 行,在 _to_ordinalf base = float(dt.toordinal())py”,第 1125 行,在转换中返回 date2num(value) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”,第 260 行,在 date2num否则:返回 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())py”,第 1125 行,在转换中返回 date2num(value) 文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/dates.py”,第 260 行,在 date2num否则:返回 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())在 _to_ordinalf 基础 = 浮动(dt.toordinal())在 _to_ordinalf 基础 = 浮动(dt.toordinal())
AttributeError:“datetime.timedelta”对象没有属性“toordinal”
我认为如果我可以将日期时间推到 xaxis 并让它计算出细节,那就太好了;没那么多。关于如何使日期适合 xaxis 的任何建议?