set title of a python `bokeh` plot figure from outside of the `figure()` function
To simply change the title without constructing a new Title
object, you can set the figure's title.text
attribute:
from bokeh.plotting import figure
p = figure()
p.title.text = 'New title'
Edit: Note that the solution in this answer will not work in bokeh server due to a known bug. This answer below will work and is more pythonic.
You have to assign an instance of Title
to p.title
. Since, we are able to investigate the types of things in python using the function type
, it is fairly simple to figure out these sorts of things.
> type(p.title)
bokeh.models.annotations.Title
Here's a complete example in a jupyter notebook:
from bokeh.models.annotations import Title
from bokeh.plotting import figure, show
import numpy as np
from bokeh.io import output_notebook
output_notebook()
x = np.arange(0, 2*np.pi, np.pi/100)
y = np.sin(x)
p = figure()
p.circle(x, y)
t = Title()
t.text = 'new title'
p.title = t
show(p)
outputs the following chart with the title set to new title
: