Python:带日期时间轴的悬停工具

Python: HoverToool with Datetime-Axis

我正在尝试为我的情节获得适当的日期时间可视化。它仅显示日期时间轴的数值。当我将鼠标悬停在绘图上时,未显示正确的日期时间。

You can see it here。

对我的代码有什么建议吗?时间戳采用 2016-01-01 00:45:00 格式。

# define source for ColumnDataSource
source = ColumnDataSource(df)
# define figure
plot = figure(plot_height=300, x_axis_type="datetime", sizing_mode="scale_width")
# add a glyph
plot.line('Datetime', 'Preis', source = source, legend='Ausgleichsenergiepreis')
# define hoverTool
hover_tool = HoverTool(tooltips=[('Time', '$Datetime'),('Price', '@Preis')], mode='vline')
hover_tool.formatters = {"Datetime": "datetime"}
plot.add_tools(hover)
# show plot
output_file('Ausgleichenergiepreise.html')
show(plot)

您可以将所需的 datetime-format 附加到您的工具提示中(参见此处:

https://docs.bokeh.org/en/latest/docs/reference/models/tools.html

在关于 HoverTool 的工具提示的部分)。这只是您代码的一小部分:

hover_tool = HoverTool(tooltips=[
    ('Time', '@Datetime{"%Y-%m-%d %H:%M:%S"}'),
    ('Price', '@Preis')], mode='vline')