简体   繁体   English

带有 python 散景的悬停工具上的日期时间格式不正确

[英]Incorrect datetime format on hovertool with python bokeh

I've got a issue with the datetime format on my hovertool.我的悬停工具上的日期时间格式有问题。 I'm not sure but i think since i've updated bokeh and pandas to the latest version (bokeh: v2.0.1 / pandas v1.0.3) in conda the presentation of the dates in my bokeh plot are faulty. I'm not sure but i think since i've updated bokeh and pandas to the latest version (bokeh: v2.0.1 / pandas v1.0.3) in conda the presentation of the dates in my bokeh plot are faulty.

import pandas as pd

# first of all i create a columndatasource and convert my datetime-strings to pandas datetime-objects:

Source = ColumnDataSource(data={'date' : pd.to_datetime(df_data['Date'], format='%Y-%m'), 
                                'values' : df_data['values']})

#print(pd.to_datetime(df_data['Datum'], format='%Y-%m'))
# >>>
#0 1980-01-01
#1 1980-02-01
#2 1980-03-01
#...

hover = HoverTool(tooltips = [('Month', '@date{%b, %Y}'),('Value', '@values{0.0} °C')],
formatters = {'date' : 'datetime'}, mode='vline')

plot = figure(x_axis_label='time',
              x_axis_type='datetime',
              y_axis_label='diff',
              tools = [hover, 'pan', 'box_zoom', 'wheel_zoom', 'reset'],
              background_fill_color = '#2F4F4F',
              output_backend="webgl",
              toolbar_location='right',
              title="Title")


plot.vbar(x = 'Month',top = 'Value', source=Source, width=timedelta(days=20), color='color')

But if i run this, it shows me for "Month" in my hovertool something like "80TiB %" and not "Apr 2020".但是如果我运行它,它会在我的 hovertool 中显示“月份”,例如“80TiB %”而不是“2020 年 4 月”。

The key in the formatters dictionary has to match the field specification exactly, including any prefix: formatters字典中的键必须与字段规范完全匹配,包括任何前缀:

formatters = {'@date' : 'datetime'}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM