I am new to Bokeh (using v2.2.1) and looking for solution to label each data point. Replicating the examples shown in documents, I could not find solutions with X axis being string,
import pandas as pd
from bokeh.models import LabelSet, ColumnDataSource
from bokeh.plotting import figure, show
output_file("weekday_val.html")
vals = pd.DataFrame({'weekday': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
'Sales': [15, 25, 36, 17, 4]})
ds = ColumnDataSource(vals)
p = figure(x_range=vals['weekday'])
p.vbar(x='weekday', width=0.75, top='Sales', source=ds)
labels = LabelSet(x='weekday', y='Sales', text='Sales', source=ds,
level='glyph',
x_offset=5,
y_offset=5,
render_mode='canvas')
p.add_layout(labels)
show(p)
It's not giving any error but it is failing to print the labels on top of the vertical bars as I was expecting. This error occurred only after I upgraded Bokeh from v1.2.0 to v2.1.1.
Does LabelSet only take numerical values for the x-axis? Is there a workaround to use this for x-axis with strings?
