Bokeh趋势/补丁图中带两个参数的Hovertool

2024-06-09 14:22:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在和Bokeh制作一个趋势图,展示概念的流行是如何随着时间的推移而来的。我使用了brewer示例(https://docs.bokeh.org/en/latest/docs/gallery/stacked_area.html)。只有工具提示没有真正显示我想要的。在

我把下面6行改成这样:

source = ColumnDataSource(data=dict(
    x=[x2] * len(areas),
    y=[areas[y] for y in categories],
    name=categories,
))
timesteps = [str(x.date()) for x in pd.date_range('1950-01-01', '1951-07-01', freq='MS')]

p = figure(x_range=FactorRange(factors=timesteps), y_range=(0, 800), tools="hover")
p.xaxis.major_label_orientation = np.pi/4
p.grid.minor_grid_line_color = '#eeeeee'
hover = p.select(dict(type=HoverTool))
hover.tooltips = [
    ('Name', ' @name'),
    ('Time', ' $x'),
    ('Count', ' @count'),
]

p.patches('x', 'y', source=source, color=colors, alpha=0.8, line_color=None)

output_file("brewer.html", title="brewer.py example")

show(p)

工具提示的前两行有效,显示了名称(y0,y1,y2…)和日期;只有第三行我搞不清。我想显示当时数据点的“高度”,也就是说,如果我有一个像

^{pr2}$

以此类推,我想在每一点显示y在给定时间点的受欢迎程度。这种受欢迎程度已经以图形方式显示出来了,但为了更明显地显示出来,我还想让绘制的数字可用——我只是不知道如何使用。 我尝试过构建不同的字典和列表,但只成功地为每个概念的每个时间点显示一个数字,但这个数字没有改变。在


Tags: 工具in概念docssourceforhtml时间