Inline Interactive Plots with Bokeh
Ensure the latest version of Bokeh is installed on your system with the following command –
On Windows
py -m pip install --upgrade bokeh
On Linux
python3 -m pip install --upgrade bokeh
To make the bokeh plots inline and interactive inside a jupyter-notebook, we can use output_notebook() and show() functions from the bokeh.io. The output_notebook() function directs the notebook to show the plot inline and show() is used to output the interactive plot. The rest is general bokeh code. This is demonstrated in the following example –
Python3
# importing the modules from bokeh.io import output_notebook, show from bokeh.plotting import figure, output_file # directing bokeh to show the output inline output_notebook() # instantiating the figure object graph = figure(title = "Bokeh Line Graph" ) # the points to be plotted x = [ 1 , 2 , 3 ] y = [ 4 , 2 , 5 ] # plotting the line graph graph.line(x, y) # displaying the model show(graph) |
Output:
The interactive controls can be seen at the top right corner of the plot.
How to Use JupyterLab Inline Interactive Plots
This article shows how to create inline interactive plots in JupyterLab with Python-3 programming language. It assumes basic familiarity with JupyterLab/Jupyter Notebooks and Python-3. By the end of the article, the reader will be able to understand and create inline interactive plots with Matplotlib, Bokeh, and Plotly plotting libraries inside a Jupyter-Notebook (in JupyterLab) using Python-3.