Non-English Column Names

Can Bokeh’s Hovertool print data if the Column name is non-English in a ColumnDataSource?

Here’s a quick example:

import pandas as pd
from bokeh.models.sources import ColumnDataSource
from bokeh.plotting import figure, show
from bokeh.models.tools import HoverTool

# Set up the data
non_english_col_name = '名前'
df = pd.DataFrame({
    non_english_col_name: ['a','b'],
    'x': [1,2],
    'y': [0,3]
})
source = ColumnDataSource(df)

# Create the glyphs
p = figure()
scatter = p.scatter(source = source)

# Create the Hovertool


hover_tool = HoverTool(renderers=[scatter],
                       tooltips=[('Name', f'@{non_english_col_name}'),
                                 ('x','@x'),
                                 ('y','@y')]
)
p.add_tools(hover_tool)
show(p)

Both x and y show up fine in the Hover, but the non-English column name (non_english_col_name) doesn’t display the data and treats it as a string literal. Is there a workaround for this other than re-naming the column name to an English name?

Screenshot 2024-02-13 at 17.51.56

@Gen column names that have spaces or sometimes other special characters in then Bokeh requires them to be enclosed in curly braces in the tooltip string. [1] Considering you are using an f-string as well, you will also have to use Python escape syntax for the literal braces, and it ends up looking like this, with three braces on each side:

tooltips=[('Name', f'@{{{non_english_col_name}}}')

This is mentioned in the middle of the Basic Tooltips section of the docs.


  1. It’s also possible to just always use curly braces around column names e.g. to be consistent and not have to worry about which cases require them. ↩︎

Thank you, this is extremely helpful. I will just always make it a rule to use curly braces!

1 Like