python - 带有空格或特殊字符的 Bokeh 工具提示名称

标签 python tooltip bokeh

我的情节正在显示???当我在列名上有空格或特殊字符时。 这是我的代码:

from bokeh.plotting import figure, show, ColumnDataSource
import pandas as pd

# prepare some data
xx = [1, 2, 3, 4, 5]
yy = [4, 5, 5, 7, 2]
df_xy = pd.DataFrame(list(zip(xx, yy)), columns=['name with space', 'y_y:y'])
#df_xy = pd.DataFrame(list(zip(xx, yy)), columns=['name', 'y'])
source = ColumnDataSource(df_xy)

pp = figure(y_range=(0, 10), sizing_mode="stretch_width", max_width=500, height=250,
    tooltips="@name with space has the value @y_y:y")
#    tooltips="@name has the value @y")

pp.circle(source.column_names[1], source.column_names[2], size=10, source=source)
pp.line(source.column_names[1], source.column_names[2], line_width=2, source=source)

# show the results
show(pp)

df是这样的

    name with space       y_y:y
0   1                     4
1   2                     5
2   3                     5
3   4                     7
4   5                     2

当我用常规名称(没有空格,没有特殊字符)更改列名时,它起作用了。

我怎样才能让它发挥作用?

最佳答案

您可以使用 "@{name with space}@{y_y:y}

tooltips="@{name with space} has the value @{y_y:y}"

顺便说一句:

如果你想格式化那么你可以使用另一个{ }

即。 @{y_y:y}{0.00} 获取点后两位数的值。

tooltips="@{name with space} has the value @{y_y:y}{0.00}"

旧版本 1.0.4 的示例显示更多 - 即多行工具提示和 formatters:

tools_hover_tooltip_formatting.py


最新文档中的其他信息:basic-tooltips

关于python - 带有空格或特殊字符的 Bokeh 工具提示名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70290537/

相关文章:

python - 如何在 BeautifulSoup 中找到 `td` 父标签的所有 `tr` 且具有 `class="Accordion-toggle main-row"' 的父标签?

python - 弹出警报的 GAE/Python 最佳实践?

工具提示 DIV 上的 CSS 箭头

python - Bokeh 和 Networkx - 悬停工具提示显示多个箭头

python - 如果我想给我的进程池更多的工作,我可以在 Pool.close() 之前调用 Pool.join() 吗?

python - python 中 not() 的顺序有什么问题?

javascript - 如何根据屏幕尺寸(重新)使用不同的选项初始化工具提示?

Extjs DataView 显示工具提示

python - 值错误: with Bokeh

javascript - Bokeh slider 堆叠条形图