This is an extantion to the already existing answer by @MarkWeston.
Let's take a look to this minimal example below:
from bokeh.io import show
from bokeh.models import ColumnDataSource, LabelSet
from bokeh.plotting import figure
p = figure()
source = ColumnDataSource(dict(x=[x for x in range(1,8)],
y=[1]*7,
names=[str(x) for x in range(1,8)]
)
)
p = figure(x_range=(0, 8), y_range=(0, 2), plot_height=100, tools='' )
labels = LabelSet(x='x', y='y', text='names', level='overlay', text_align='center',
x_offset=0, y_offset=-8, source=source, render_mode='canvas')
p.add_layout(labels)
p.circle(x='x', y='y', radius=0.3, alpha=0.3, source=source)
p.xgrid.visible = False
p.ygrid.visible = False
p.xaxis.visible = False
p.yaxis.visible = False
show(p)
This is the output of the example.
Now we can follow the answer by @MarkWeston and set the parameter we want beforehand.
If you create a LabelSet you can pass all parameters explained in the documentation of LabelSet.
But there is also a second way, if you want to change your settings after calling p.add_layout().
The function p.add_layout(labels) comes with a parameter called place. Valid values are left, right, above, below and the default value center. For more see also the documentation to add_layout.
For simplification let's assume that you call the add_layout() function with the default value center. Now we need to now, at which index of the list contained in p.center our LabelSet is placed.
We can get this information by running
[i for i, item in enumerate(p.center) if isinstance(item, LabelSet)]
>>> [2]
which will return "2". Note that at 0 and 1 there are the invisible grids.
Now we can change our parameter settings of this LabelSet calling lines like
p.center[2].text_color = {'value':'#0000ff'}
p.center[2].text_size = {'value':'11pt'}
p.center[2].text_size = 'TimesNewRoman'
and many more.
If you plot the figure again with show(p) you can see the changes and it looks like
this.