如何更改散景悬浮工具中显示的日期/时间格式?



目前散景悬浮工具将我的日期值显示为13位数字。如何更改它的显示格式?

下面是我的代码…我还指定了日期/时间在哪一行代码中。
from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.io import output_notebook
x = dff.P2_VWC
y = dff.P2_EC
bok = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
bok.line(x, y, legend_label="Hysteresis", line_width=2)
show(bok)
output_notebook()
#Specify the selection tools to be made available
select_tools = ['box_select', 'lasso_select', 'poly_select', 'tap', 'reset']
# Format the tooltip
tooltips = [ 
('VWC', '@P2_VWC'),
('EC', '@P2_EC'),
('Date', '@date_time') # !THIS DATE NEEDS FORMATTED!
]
p = figure(plot_width=800, plot_height=400, x_axis_type='linear', title = "VWC v. Bulk EC")
p.line(x="P2_VWC", y="P2_EC", source=dff)
p.xaxis.axis_label = 'VWC'
p.yaxis.axis_label = 'Bulk EC'
p.add_tools(HoverTool(tooltips=tooltips))
show(p)
感谢您的宝贵时间!

只有几行代码需要更改,但它们在下面。{%F %T}可以添加到日期/时间代码中,以指定您想要的内容。

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.io import output_notebook
output_notebook()
#Specify the selection tools to be made available
select_tools = ['box_select', 'lasso_select', 'poly_select', 'tap', 'reset']
# Format the tooltip
# https://docs.bokeh.org/en/latest/docs/reference/models/formatters.html#bokeh.models.formatters.DatetimeTickFormatter
tooltips = [ 
('VWC', '@P2_VWC'),
('EC', '@P2_EC'),
('Date', '@date_time{%F %T}'),
]
p = figure(plot_width=800, plot_height=800, x_axis_type='linear', title = "VWC v. Bulk EC")
p.line(x="P2_VWC", y="P2_EC", source=df1)
p.xaxis.axis_label = 'VWC'
p.yaxis.axis_label = 'Bulk EC'
p.add_tools(HoverTool(tooltips=tooltips, formatters={'@date_time': 'datetime'}))
show(p)

最新更新