我有过
dt_source = ColumnDataSource(
{
"date": result_detail['report_date_as_yyyy_mm_dd']
,"contract": result_detail['contract_name']
,"open_interest": result_detail['open_interest']
}
)
tools="wheel_zoom,reset,save,crosshair,pan,box_zoom"
oi = figure(plot_width=800, plot_height=200, x_axis_type="datetime", tools=tools, title="Open Interest")
oi.line(x="date", y="open_interest", source=dt_source)
oi.title_text_font_size = value("12pt")
oi.ygrid.grid_line_color = None
oi.yaxis.minor_tick_line_color = None
oi.xgrid.grid_line_dash = "dashed"
#adjust what information you get when you hover over it
oi_tooltips = """
<span face="font-family: Arial, Helvetica, sans-serif">
<div>
<span style="font-size: 15px;">@contract</span>
<span style="font-size: 10px; color: #666;">@signal</span>
</div>
<div style="line-height: 1;">
<span style="font-size: 10px; color: #666; white-space:pre;">Open Interest 	 @open_interest{1,1}</span>
</div>
<div style="line-height: 1;">
<span style="font-size: 10px; color: #666; white-space:pre;">Date 	 	 	 @date</span>
</div>
</span>
"""
oi_hover = HoverTool(tooltips=oi_tooltips)
oi.add_tools(oi_hover)
问题出在日期(Date 	 	 	 @date
),它在悬停工具中显示为纪元时间。
我试过了:
@date
@date{date}
@date{datetime}
@date{dd/mm/yyyy}
@date{"dd/mm/yyyy"}
使用html.中的悬停工具,我想知道日期类型的格式设置选项,特别是以下任一项的格式设置:。
yyyy-mm-dd
dd/mm/yyyy
dt_source
使用的是从Postgresql中提取的数据,它调用的过程返回的是date类型。运行result_detail["report_date_as_yyyy_mm_dd"]
会带来以下好处:
0 2016-01-26
1 2016-01-19
2 2016-01-12
3 2016-01-05
...
发布于 2016-02-04 05:13:01
自从这个答案最初发布以来,Bokeh已经进行了新的工作,以使事情变得更简单。通过指定格式化程序,可以通过悬停工具直接将日期时间字段格式化为日期时间,例如:
HoverTool(tooltips=[('date', '@date_col{%F}')],
formatters={'date_col': 'datetime'})
不再需要预先格式化数据源中的日期字段,如下所示。有关更多信息,请参阅Formatting Tooltip Fields
的老答案:
截至2016年2月4日,没有快捷方法,issue is currently open请求该功能在悬停工具中格式化日期/时间值。
问题页面上还提供了当前可以使用的解决方法:
为了解决这个问题,我需要添加一个只有一个字段的ColumnDataSource,如下所示:
source = ColumnDataSource(data=dict( time=df.map(lambda x: x.strftime('%d-%m-%Y')) ))
然后我告诉我的工具提示显示("time", "@time")
。
https://stackoverflow.com/questions/35128934
复制相似问题