什么是正确的方式来改变Bokeh python中的工具提示的颜色?
问题描述:
目标:了解如何更改Python中Bokeh工具提示的背景颜色。什么是正确的方式来改变Bokeh python中的工具提示的颜色?
下面是对我的作品的代码,但我似乎无法在提示中调整颜色(目前这只能产生一个白色背景的工具提示/悬停):
# Sometimes Bokeh is to verbose
import warnings
warnings.filterwarnings('ignore')
# Develop a histogram
from bokeh.charts import Bar, output_file, show
# Information contained within the hoover
tooltips=[
('Age', '@Age'),
('Count', '@height{0,000}')
]
colormap = {'Age':'gray'}
colors = colormap
from bokeh.palettes import brewer
#palette = brewer["Blues"][3]
# Create chart
p = Bar(data, 'Age', values='Age', title="Hep-C Age",xlabel="Age", ylabel="Number of Observations",
agg='count',
tooltips=tooltips, legend=False,plot_width=600, plot_height=400,
tools="lasso_select,box_select,tap,box_zoom,reset,save", active_drag="lasso_select",
toolbar_location="above",color="gray",title_text_font_size='14pt',title_text_color="gray")
答
基于亚历克斯我成功地找到了解决办法:
hover = HoverTool(tooltips="""
<div style ="border-style: solid;border-width: 15px;background-color:black;">
<div>
<span style="font-size: 12px; color: white;font-family:century gothic;">@height{0,000}</span>
<span style="font-size: 12px; color: white;font-family:century gothic;"> Observations</span>
</div>
</div>
可能矫枉过正,并有一个更简单的方法,但你可以使用[自定义HTML模板(https://bokeh.pydata.org/en/latest/docs/user_guide/tools.html #custom-tooltip)为你的工具提示。 – Alex