2

I have some trouble with formatting the displayed values of the hoover tool. This is the relevant code for my stacked vbar plot:

p.vbar_stack(sports, x='dates', width=70000000, color=colors, source=plot_data,
             legend=[value(x) for x in sports])
p.add_tools(HoverTool(
    tooltips=[
        ("Duration", "@$name min"),  # values of 'name' are in nanoseconds
        ("Sport", "$name"),
    ]))

which leads to this output: bokeh_plot

But instead of having the Duration being displayed in nano seconds I would like to display it in a HH:MM format or at least in float like minutes or hours format.

I also tried to add an formatter like described in this post with no success.

The data from the variable plot_data looks as follows:

plot_data = {'Hiking': array([0, 0, 0, 13090000000000,
                              13417000000000, 0, 14680000000000, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0, 0,
                              0, 0, 0],
                             dtype='timedelta64[ns]'),
             'dates': [datetime.date(2019, 12, 25), datetime.date(2019, 12, 26), datetime.date(2019, 12, 27),
                       datetime.date(2019, 12, 28), datetime.date(2019, 12, 29), datetime.date(2019, 12, 30),
                       datetime.date(2019, 12, 31), datetime.date(2020, 1, 1), datetime.date(2020, 1, 2),
                       datetime.date(2020, 1, 3), datetime.date(2020, 1, 4), datetime.date(2020, 1, 5),
                       datetime.date(2020, 1, 6), datetime.date(2020, 1, 7), datetime.date(2020, 1, 8),
                       datetime.date(2020, 1, 9), datetime.date(2020, 1, 10), datetime.date(2020, 1, 11),
                       datetime.date(2020, 1, 12), datetime.date(2020, 1, 13), datetime.date(2020, 1, 14),
                       datetime.date(2020, 1, 15), datetime.date(2020, 1, 16), datetime.date(2020, 1, 17),
                       datetime.date(2020, 1, 18), datetime.date(2020, 1, 19), datetime.date(2020, 1, 20),
                       datetime.date(2020, 1, 21), datetime.date(2020, 1, 22), datetime.date(2020, 1, 23),
                       datetime.date(2020, 1, 24)]}

So here I can see the values being in nano seconds. Still bokeh kind of knows how many hours it is since the height of the vbars are aligned with the y-axis which is in hours automatically.

So I guess it should be possible to somehow convert the nano seconds into hours or similar.

Fabs
  • 161
  • 1
  • 9

0 Answers0