当 x 轴在日期时间时用散景绘制射线
Draw a Ray with Bokeh when x axis is in datetime
尝试在我的数据集中的一个重要日期绘制垂直射线以突出显示该日期的趋势 before/after。我了解如何使用不在日期时间的 x 轴绘制射线,但我一直在努力让它在 x 处于日期时间时工作。这是我尝试过的:
from bokeh.plotting import figure, output_file, show
from datetime import datetime as dt
from math import pi
p = figure(title = 'stuff',
x_axis = 'date',
y_axis = datapoints,
x_axis_type = "datetime",
tools='pan, wheel_zoom, box_zoom, reset, resize, previewsave',
plot_width=1000)
#dates and data are lists containing datetime objects and y values
p.line(dates, data, line_width=1)
p.xaxis.major_label_orientation = pi/4
p.ray(x = dt(year, month, day), y = 0, length = 0, angle_units = "deg",
angle = 90, color = 'black')
output_file('data.html')
show(p)
这会产生很长的堆栈跟踪,并出现以下错误:
ValueError: expected an element of either String, Dict(String, Either(String, Instance(Transform), Instance(ColorMapper), Float)) or Float, got datetime.datetime(2014, 9, 18, 0, 0)
当 x 轴处于日期时间时,这是否根本不受支持,或者我是否遗漏了文档中的某些内容?
想通了。我最初为我的 x 轴传入了一个日期时间对象列表。我将该列表替换为以毫秒为单位的时间戳列表,然后为 call-out 日期获取相应的以毫秒为单位的时间戳,并使用它来定义射线。
修改后的代码:
p.line(lst_of_epoch_times_ms, data, line_width=1)
p.xaxis.major_label_orientation = pi/4
p.ray(x = ms_timestamp_callout, y = 0, length = 0, angle_units = "deg",
angle = 90, color = 'black')
希望这对遇到这个问题的人有所帮助。
按照指示使用 Span here
Span annotations are lines that are orthogonal to the x or y axis of a plot. They have a single dimension (width or height) and go from one edge of the plot area to the opposite edge.
尝试在我的数据集中的一个重要日期绘制垂直射线以突出显示该日期的趋势 before/after。我了解如何使用不在日期时间的 x 轴绘制射线,但我一直在努力让它在 x 处于日期时间时工作。这是我尝试过的:
from bokeh.plotting import figure, output_file, show
from datetime import datetime as dt
from math import pi
p = figure(title = 'stuff',
x_axis = 'date',
y_axis = datapoints,
x_axis_type = "datetime",
tools='pan, wheel_zoom, box_zoom, reset, resize, previewsave',
plot_width=1000)
#dates and data are lists containing datetime objects and y values
p.line(dates, data, line_width=1)
p.xaxis.major_label_orientation = pi/4
p.ray(x = dt(year, month, day), y = 0, length = 0, angle_units = "deg",
angle = 90, color = 'black')
output_file('data.html')
show(p)
这会产生很长的堆栈跟踪,并出现以下错误:
ValueError: expected an element of either String, Dict(String, Either(String, Instance(Transform), Instance(ColorMapper), Float)) or Float, got datetime.datetime(2014, 9, 18, 0, 0)
当 x 轴处于日期时间时,这是否根本不受支持,或者我是否遗漏了文档中的某些内容?
想通了。我最初为我的 x 轴传入了一个日期时间对象列表。我将该列表替换为以毫秒为单位的时间戳列表,然后为 call-out 日期获取相应的以毫秒为单位的时间戳,并使用它来定义射线。 修改后的代码:
p.line(lst_of_epoch_times_ms, data, line_width=1)
p.xaxis.major_label_orientation = pi/4
p.ray(x = ms_timestamp_callout, y = 0, length = 0, angle_units = "deg",
angle = 90, color = 'black')
希望这对遇到这个问题的人有所帮助。
按照指示使用 Span here
Span annotations are lines that are orthogonal to the x or y axis of a plot. They have a single dimension (width or height) and go from one edge of the plot area to the opposite edge.