首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在堆叠条形图中包含Bokeh工具提示

问在堆叠条形图中包含Bokeh工具提示
EN

Stack Overflow用户
提问于 2019-03-18 11:24:25
回答 2查看 1.2K关注 0票数 1

我有下面的代码。谁能让我知道如何在下面的条形图中包含工具提示。

代码语言:javascript
复制
from bokeh.core.properties import value
from bokeh.io import show, output_file
from bokeh.plotting import figure

output_file("stacked.html")

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
years = ["2015", "2016", "2017"]
colors = ["#c9d9d3", "#718dbf", "#e84d60"]

data = {'fruits' : fruits,
        '2015'   : [2, 1, 4, 3, 2, 4],
        '2016'   : [5, 3, 4, 2, 4, 6],
        '2017'   : [3, 2, 4, 4, 5, 3]}

p = figure(x_range=fruits, plot_height=250, title="Fruit Counts by Year",
           toolbar_location=None, tools="")

p.vbar_stack(years, x='fruits', width=0.9, color=colors, source=data,
             legend=[value(x) for x in years])

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xgrid.grid_line_color = None
p.axis.minor_tick_line_color = None
p.outline_line_color = None
p.legend.location = "top_left"
p.legend.orientation = "horizontal"

show(p)

谢谢

迈克尔

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-03-18 18:17:11

您希望工具提示按年指示值:

代码语言:javascript
复制
tooltips = [
    ("fruit", "@fruits"),
    ("2015:", "@2015"),
    ("2016:", "@2016"),
    ("2017:", "@2017"),
]

p = figure(x_range=fruits, plot_height=300, title="Fruit Counts by Year",
           tooltips=tooltips,
           toolbar_location="right", tools="")

输出:

​

​

票数 2
EN

Stack Overflow用户

发布于 2019-03-18 16:26:09

您可以通过在带有工具的列表中指定"hover“并向其添加工具提示来添加悬停工具。您有两种工具提示:"@“显示源数据和$,它们对应于绘图固有的值,例如鼠标在数据或屏幕空间中的坐标。Hovertools很容易与ColumnDataSource结合使用,所以也可以看看这一点。有关悬浮工具的更多信息,请访问here。

将悬停工具添加到绘图中可以通过更改以下线条来完成:

代码语言:javascript
复制
tooltips = [
    ("fruit", "@fruits"),
    ("x, y", "$x,$y"),
]

p = figure(x_range=fruits, plot_height=300, title="Fruit Counts by Year",
           toolbar_location="right", tools=["hover"], tooltips = tooltips)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55214348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档