Matplotlib and Seaborn produce static plots, whereas Bokeh produces interactive plots. This means when the user interacts with these plots, they change accordingly.
Plots can be embedded as output of Flask or Django enabled web applications. Jupyter notebook can also be used to render these plots.
Dependencies of Bokeh −
Numpy Pillow Jinja2 Packaging Pyyaml Six Tornado Python−dateutil
Installation of Bokeh on Windows command prompt
pip3 install bokeh
Installation of Bokeh on Anaconda prompt
conda install bokeh
Following is an example −
from bokeh.plotting import figure, output_file, show import numpy as np import math x = np.arange(0, math.pi*3.5, 0.09) fig = figure() fig.line(x, np.sin(x),line_width = 2, line_color = 'navy', legend = 'sine') fig.circle(x,np.cos(x), line_width = 2, line_color = 'orange', legend = 'cosine') fig.square(x,np.tan(x),line_width = 2, line_color = 'cyan', legend = 'tan') show(fig)
The required packages are imported, and aliased.
The figure function is called.
The ‘arange’ function in NumPy is used to generate data.
The ‘output_file’ function is called to mention the name of the html file that will be generated.
The ‘line’, ‘circle’, and ‘square’ functions present in Bokeh are called, along with data.
The ‘show’ function is used to display the plot.