I would like to have stylized tooltips (specifically, background color) upon hovering on a scatterplot’s points. The plot is rendered in the browser. It’s straightforward to get the tooltips with HoverTool, but I cannot stylize the tooltips the way I wanted. I tried customizing the tooltip by setting the tooltips parameter to something like
Which indeed creates a black box in the tooltip, but the black box is surrounded by the larger “default” white box. It seems no matter what I do, the changes only affect what’s inside the “default” box, not the box itself.
By looking at the bokeh.js file that is loaded in the html, I found that style defaults for the hover tooltip are set there:
Hi, thanks for the reply. I tried with stylesheets, but i couldn’t make it work. I may be doing something wrong, applying the style to the figure? Example:
from bokeh.models import ColumnDataSource, InlineStyleSheet, HoverTool
from bokeh.plotting import figure
from bokeh.io import show
data = {
'x': [1, 2, 3, 4, 5],
'y': [6, 7, 2, 4, 5],
}
source = ColumnDataSource(data)
# set the hover style
stylesheet = InlineStyleSheet(css=""":host{tooltip-color:black;}""")
p = figure(height=400, width=400, stylesheets=[stylesheet])
p.scatter(x='x', y='y', source=source)
hover = HoverTool(mode="vline")
p.add_tools(hover)
show(p)
Since I don’t have much experience with CSS, I just mindlessly tried the snipped above with GlobalInlineStyleSheet as well.
I’ve confirmed that changing the --tooltip-color color from the inspector (with JS paused) changes the color of the tooltip. However, I can’t seem to set it via bokeh’s stylesheets because I think it’s created programmatically by the JS code every time I hover on a point.
I might be wrong, because my knowledge in this area is quite limited.