Python 3.10. Bokeh 2.4.3
I have searched and searched but I can’t find a solution.
I’m trying to get a euro sign (€) to appear in a Bokeh HoverTool tooltip. The dollar sign is pretty easy to do:
hover.tooltips = [ ('Post', '@Post'), ('Bedrag', '@Bedrag{$ 0.00}') ]
Changing the $ to a € doesn’t do anything.
I’ve tried to somehow use the PrintfTickFormatter
with hover.formatters
but while the formatter works fine for one of the axis in the figure itself (figVbar.yaxis[0].formatter = PrintfTickFormatter(format="€ %s")
), I can’t get it to work with a hovertooltip.
Can someone point me in the right direction?
Advertisement
Answer
One easy modification do get this done is to specify the formatters
and use the PrintfTickFormatter
in the Hovertool .
The definition of the HoverTool could look like this:
HoverTool( tooltips=[ ('Post', '@Post'), ('Bedrag', '@Bedrag{€ %.2f}') # use the format for floats (with 2 digits) ], formatters={"@Bedrag": "printf"}, # activate the PrintfTickFormatter )
Minimal Example
from bokeh.plotting import figure, show, output_notebook from bokeh.models import ColumnDataSource, HoverTool output_notebook() source = ColumnDataSource({'index':[0,1,2], 'Post':[1,2,3],'Bedrag':[3,4,5]}) p=figure(width=300, height=300) bar = p.vbar(x='index', top='Post', source=source, width=0.8) p.add_tools( HoverTool( tooltips=[ ('Post', '@Post'), ('Bedrag', '@Bedrag{€ %.2f}') ], formatters={"@Bedrag": "printf"}, renderers=[bar], ) ) show(p)
Output