我正在尝试将一个简单的文本字符串(字形)添加到使用的散景图中x_axis_type='datetime'
我的代码(精简到其要点)如下:
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...
是否有散景函数(或 datetime.date 的属性)可以为我提供散景图期望的值?
非常感谢。
注意:我尝试过使用x = bokeh.properties.Date(dt)
但这给了我:
ValueError: expected an element of either String,
Dict(String, Either(String, Float)) or Float, got <bokeh.properties.Date object