Search code examples
pythonbokehinteractive

HoverTool problems, bokeh. Shows "???" when signs (/, -) or special letters (æ,ø,å) are given


I am trying to build a stacked barchat in bokeh over the different tree types in the different districts in Copenhagen. I have succeded in building a chart but also want it to include a HoverTool. My code is as seen below:

p = figure(x_range = districtName,plot_width = 900, plot_height=400, 
           title='Tree pr. district',toolbar_location= None)

# Stacked bar chart
renderers = p.vbar_stack(stackers=treeName,x='bydelsnavn',source=temp,
            width=0.5, color = colornames)

# Add the hover tool
for r in renderers:
    tree = r.name
    hover = HoverTool(tooltips=[
        ("%s" % tree, "@%s" % tree)
    ], renderers = [r])
    p.add_tools(hover)

p.xaxis.axis_label = 'Copenhagen city cistricts'
p.yaxis.axis_label = 'Tree counts'

show(p)

The hovertool works fine for the treeNames whichs do not have the danish letters 'ø', 'æ' or 'å' in them or a sign like '/' or '-'. For example for the treeName Kirsebær/blomme the hover tool shows ???ær/blomme. So I am assuming it is because of the wierd letters and signs.

Below are the districtName and a bit of the treeName.

districtName = ['Vesterbro-Kongens Enghave', 'Indre By', 'Nørrebro', 'Valby',
       'Vanløse', 'Bispebjerg', 'Brønshøj-Husum', 'Amager Øst',
       'Østerbro', 'Amager Vest']
treeName = ['Lind', 'Kirsebær/Blomme', 'Tjørn', 'Robinie',
       'Kastanie', 'Valnød', 'Hestekastanie', 'Poppel', 'Ask', 'Eg',
       'Løn', 'Platan', 'Avnbøg', 'Røn', 'Skyrækker', 'Tretorn',
       'Trompetkrone', 'Pil', 'Tulipantræ', 'Hassel', 'Birk', ........

How can I solve this problem? :-)


Solution

  • Wrap the values in {}:

    ("%s" % tree, "@{%s}" % tree)