这里是Python的第一篇新文章,所以对我轻松一点!
我使用bokeh库在python中绘制了可视化效果。我使用了hovertool函数,但是将鼠标悬停在它上面时似乎无法显示任何数据。不知道我在哪里错了。任何支持的欢迎。
from bokeh.plotting import figure, show
from bokeh.io import output_file
from bokeh.models import ColumnDataSource, NumeralTickFormatter
from bokeh.models import HoverTool
output_notebook()
df = ColumnDataSource(contents)
select_tools = ['box_select', 'lasso_select', 'poly_select', 'tap', 'reset']
fig = figure(plot_height=400,
plot_width=600,
x_axis_label=' Store Average Age of Respondent',
y_axis_label=' Store NPS Percentage Score %',
title='MNWIOM Average Customer Age Vs. NPS Percentage Score by Store',
toolbar_location='below',
tools=select_tools)
fig.square(x='Average Age of Respondent',
y='NPS Percentage Score',
source=df,
color='royalblue',
selection_color='deepskyblue',
nonselection_color='lightgray',
nonselection_alpha=0.3)
tooltips = [('Store','@Store Name'),
('Average Customer Age', '@Average Age of Respondent'),
('NPS Score %', '@NPS Percentage Score'),]
hover_glyph = fig.circle(x='Average Age of Respondent', y='NPS Percentage Score', source=df,
size=15, alpha=0,
hover_fill_color='black', hover_alpha=0.5)
fig.add_tools(HoverTool(tooltips=tooltips, renderers=[hover_glyph]))
show(fig)
答案 0 :(得分:1)
如果字段名中有空格,则必须在工具提示定义中使用大括号{}。来自hovertool文档(link):
tooltips=[
( 'date', '@date{%F}' ),
( 'close', '$@{adj close}{%0.2f}' ), # use @{ } for field names with spaces
( 'volume', '@volume{0.00 a}' ),
]
答案 1 :(得分:0)
我会在图形变量中使用Hovertool。
productQuantity