[英]Bokeh HoverTool datetime formatter not working
My code for the bokeh HoverTool is the following:我的散景 HoverTool 代码如下:
p = figure(
plot_height=250,
x_axis_type='datetime',
)
p.vbar(x=data_df['date'].dt.to_pydatetime(), top=data_df['data'].values, width=datetime.timedelta(1))
hover_tool = HoverTool(
tooltips=[('Count', '@top'), ('Date', '@x')], mode='vline', formatters={'$x': 'datetime'}
)
p.add_tools(hover_tool)
I still get the numeric format of the date as can be seen on the image.我仍然可以在图像上看到日期的数字格式。 I tried formatters={'@x': 'datetime'}
with no luck.我试过formatters={'@x': 'datetime'}
没有运气。
Your solution works, if you use $x
instead of @x
and add one of the listed formats supported by the DatetimeTickFormatter
to ('Date', '$x')
like ('Date', '$x{%F}')
.您的解决方案有效,如果您使用$x
而不是@x
并将DatetimeTickFormatter
支持的列出格式之一添加到('Date', '$x')
像('Date', '$x{%F}')
. There are plenty of options and you can select the one you prefere the most.有很多选择,您可以选择您最喜欢的一个。
Minimal Example最小的例子
import pandas as pd
from bokeh.plotting import show, figure, output_notebook
from bokeh.models import HoverTool, ColumnDataSource
output_notebook()
data_df = pd.DataFrame({'date':pd.date_range('2022-05-13', freq='D', periods=10), 'top':list(range(10))})
p = figure(
plot_height=250,
x_axis_type='datetime',
)
p.vbar(x=data_df['date'], top=data_df['top'], width=pd.Timedelta('12H'))
hover_tool = HoverTool(
tooltips=[('Count', '@top'), ('Date', '$x{%F}')], mode='vline', formatters={"$x": "datetime"}
)
p.add_tools(hover_tool)
show(p)
Comment:评论:
I don't know why there is no working default, but maybe because there are so many options, that any default would be somehow wrong.我不知道为什么没有有效的默认值,但可能是因为有太多选项,任何默认值都会在某种程度上是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.