我试图在使用x_axis_type='datetime'
的Bokeh图中添加一个简单的文本字符串(字形)。
我的代码(仅保留必要部分)如下:
p = figure(plot_width=900, plot_height=380, x_axis_type='datetime')
dt = date(2003, 3, 15)
p.line(xvals, yvals)
txt = Text(
# x=some_formatting_function(dt),
x=1057005600000,
y=0.1,
text=["happy day!"],
text_align="left",
text_baseline="middle",
text_font_size="11pt",
text_font_style="italic",
)
p.add_glyph(txt)
show(p)
X轴范围/数值(即日期)从2002年到2006年,我想在2003年添加文本。我在上面的代码中显示的X值(即1057005600000——通过试错得出)将标志放在了正确的位置。
但是,我无法直接使用datetime.date来解决这个问题...
是否有一种bokeh函数(或datetime.date的属性)可以提供bokeh图所期望的值?
非常感谢。
注:我尝试使用
x = bokeh.properties.Date(dt)
,但这给了我:ValueError: expected an element of either String,
Dict(String, Either(String, Float)) or Float, got <bokeh.properties.Date object