散景图:悬停工具提示
Bokeh Charts: HoverTool tips
Bokeh 可以在图表上显示悬停工具提示,从值列表中进行选择。但是,如果我需要使所有值的变量都相同怎么办?
下面的示例(来自文档)允许显示列表中的值,但是如果您这样做 desc=foo,
,而不是 desc=['A', 'b']
,提示将转换为“???”
source = ColumnDataSource(
data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
desc=['A', 'b', 'C', 'd', 'E'],
)
)
hover = HoverTool(
tooltips=[
("index", "$index"),
("(x,y)", "($x, $y)"),
("desc", "@desc"),
]
)
ColumnDataSource
数据字典要求与每个键关联的所有列表的长度相同。让我们在 ColumnDataSource
块之前声明一些变量:
x_ls = [1, 2, 3, 4, 5]
foo_ls = ['foo']*len(x)
print(foo_ls) #['foo', 'foo', 'foo', 'foo', 'foo']
source = ColumnDataSource(
data=dict(
x=x_ls,
y=[2, 5, 8, 2, 7],
desc=foo_ls
)
)
这将根据需要显示所有 5 个点的 'foo'。我试图说明问题的其他一些负面案例:
desc=foo
这会引发错误,因为 HoverTool 不知道 foo 是什么。
desc='foo'
其中一个会显示'f',另外两个会显示'o',最后两个会显示'???'
desc=['foo']
其中一个点将显示 'foo',其他点将显示“???”
Bokeh 可以在图表上显示悬停工具提示,从值列表中进行选择。但是,如果我需要使所有值的变量都相同怎么办?
下面的示例(来自文档)允许显示列表中的值,但是如果您这样做 desc=foo,
,而不是 desc=['A', 'b']
,提示将转换为“???”
source = ColumnDataSource(
data=dict(
x=[1, 2, 3, 4, 5],
y=[2, 5, 8, 2, 7],
desc=['A', 'b', 'C', 'd', 'E'],
)
)
hover = HoverTool(
tooltips=[
("index", "$index"),
("(x,y)", "($x, $y)"),
("desc", "@desc"),
]
)
ColumnDataSource
数据字典要求与每个键关联的所有列表的长度相同。让我们在 ColumnDataSource
块之前声明一些变量:
x_ls = [1, 2, 3, 4, 5]
foo_ls = ['foo']*len(x)
print(foo_ls) #['foo', 'foo', 'foo', 'foo', 'foo']
source = ColumnDataSource(
data=dict(
x=x_ls,
y=[2, 5, 8, 2, 7],
desc=foo_ls
)
)
这将根据需要显示所有 5 个点的 'foo'。我试图说明问题的其他一些负面案例:
desc=foo
这会引发错误,因为 HoverTool 不知道 foo 是什么。
desc='foo'
其中一个会显示'f',另外两个会显示'o',最后两个会显示'???'
desc=['foo']
其中一个点将显示 'foo',其他点将显示“???”