To use bokeh you need to launch a bokeh server and connect to it using a browser. We will use this example script (hello_world.py
):
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import curdoc
def modify_doc(doc):
"""Add a plotted function to the document.
Arguments:
doc: A bokeh document to which elements can be added.
"""
x_values = range(10)
y_values = [x ** 2 for x in x_values]
data_source = ColumnDataSource(data=dict(x=x_values, y=y_values))
plot = figure(title="f(x) = x^2",
tools="crosshair,pan,reset,save,wheel_zoom",)
plot.line('x', 'y', source=data_source, line_width=3, line_alpha=0.6)
doc.add_root(plot)
doc.title = "Hello World"
def main():
modify_doc(curdoc())
main()
To launch it you need to execute bokeh on the command line and use the serve
command to launch the server:
$ bokeh serve --show hello_world.py
The --show
parameter tells bokeh to open a browser window and show document defined in hello_world.py
.