我正在尝试使用Bokeh创建一个带有日期时间x轴的条形图。 我使用了几个时间分辨率,除了周之外,其他都可以正常工作。 我有一个类似这样的pandas数据框(我添加了“Week”列用于参考,它不应保留)
Timestamp ResultID
2017-12-03 106
2017-11-26 381
2017-11-19 406
2017-11-12 662
2017-11-05 656
2017-10-29 638
2017-10-22 429
2017-10-15 784
带日期的输出
您可以看到标签错位并且有时缺失。看起来Bokeh总是显示每个月的第一天,而不管它是否是一周的第一天。这会使其他标签位置偏移。我似乎找不到任何文档来帮助解决这个问题。我也不能使用分类轴,因为我正在设置范围以仅显示最近的7个区间,这样会导致分类轴出现问题。我还尝试更改标签的格式以显示日历周标签,但也没有成功。有什么想法可以使标签与相应的列匹配吗?
bintime = 'W'
bins = {'h' : '%Y-%m-%d %H:%M', 'D' : '%F', 'W' : '%F', 'M' : '%Y-%m'}
widths = {'h' : 3600000, 'D' : 86400000, 'W' : 604800000, 'M' : 2419200000}
pad = 0.9
source = ColumnDataSource(df)
now = np.datetime64(datetime.datetime.now())
if bintime == 'M':
padspace = now + np.timedelta64(1*30, 'D')
dispdelta = now - np.timedelta64(7*30, 'D')
else:
padspace = now
dispdelta = now - np.timedelta64(7, bintime)
ranges = ['hours', 'days', 'months']
#xrange = df.DT.tolist()
xrange = (dispdelta, padspace)
output = figure(plot_height=300, width=800, title="MPL Output", x_range=xrange, tools ='xpan,reset,xzoom_in,xzoom_out')
output.vbar(x='Timestamp', top='ResultID', width=widths[bintime]*pad, source=source)
output.xaxis.formatter=DatetimeTickFormatter(hours=bins[bintime], days=bins[bintime], months=bins[bintime])
show(output)