bokeh.sphinxext#
Sphinx extensions for including Bokeh content in Sphinx documentation.
bokeh_plot#
Include Bokeh plots in Sphinx HTML documentation.
For other output types, the placeholder text [graph]
will
be generated.
The bokeh-plot
directive can be used by either supplying:
A path to a source file as the argument to the directive:
.. bokeh-plot:: path/to/plot.py
Inline code as the content of the directive:
.. bokeh-plot::
from bokeh.plotting import figure, output_file, show
output_file("example.html")
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
p = figure(title="example", width=300, height=300)
p.line(x, y, line_width=2)
p.scatter(x, y, size=10, fill_color="white")
show(p)
This directive also works in conjunction with Sphinx autodoc, when used in docstrings.
The bokeh-plot
directive accepts the following options:
- process-docstring (bool):
Whether to display the docstring in a formatted block separate from the source.
- source-position (enum(‘above’, ‘below’, ‘none’)):
Where to locate the block of formatted source code (if anywhere).
- linenos (bool):
Whether to display line numbers along with the source.
Examples
The inline example code above produces the following output:
from bokeh.plotting import figure, output_file, show
output_file("example.html")
x = [1, 2, 3, 4, 5]
y = [6, 7, 6, 4, 5]
p = figure(title="example", width=300, height=300)
p.line(x, y, line_width=2)
p.scatter(x, y, size=10, fill_color="white")
show(p)
To enable this extension, add “bokeh.sphinxext.bokeh_plot” to the extensions list in your Sphinx configuration module.