I am trying to make a bar chart from Bokeh with a Datetime x-axis. I am using several time resolutions, and I can get all of them to work except for the weeks. I have a pandas dataframe that looks like this (I added the 'Week' column for reference, it shouldn't stay)
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
You can see that the labels are misaligned and sometimes missing. It looks like Bokeh is always displaying the first day of the month regardless of if it is the first day of the week or not. this then shifts the other labels out of position. I can't seem to find any documentation that would help to do this. I also can't use a categorical axis because the way that I am setting ranges to only show the 7 most recent bins will break. I've also tried changing the format of the labels to show the calendar week labels but no luck there either. Any ideas on how to get the labels to match with the appropriate columns?
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)