Now Reading
Hands-On Tutorial on Bokeh – Open Source Python Library For Interactive Visualizations

Hands-On Tutorial on Bokeh – Open Source Python Library For Interactive Visualizations

Bokeh Tutorial

Dashboards are collections of bars, charts, and graphs that help us visualize different attributes of a dataset. A dashboard works as a graphical user interface which helps us identify the key performance indicators relevant to the dataset or the particular business model. Python provides different open-source libraries that can help you create your own dashboard with your dataset. Today we will be talking about Bokeh which is an open-source python library for interactive visualizations for the modern web browsers. 

Bokeh provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets. It can be used for different purposes like creating interactive plots, dashboards, and even data-driven applications.

Register for our upcoming Masterclass>>

In this article we will discuss:

  1. Creating Bokeh Visualization and Analyzing it.
  2. Creating a Sales Dashboard using Bokeh

Implementation of Bokeh:

Like any other library, we need to install Bokeh for exploring it by pip install bokeh

  1. Importing required libraries

We will import pandas for loading the dataset and will import different functions of bokeh as and when required.

Looking for a job change? Let us help you.

import pandas as pd

from bokeh.plotting import figure, output_file, show

  1. Loading the dataset

We will create a sales dashboard for which we need sales data of a company, here I will use a dataset which contains Sales of a company and different attributes on which it depends.

df = pd.read_csv(‘Advertising.csv’)


  1. Creating Visualizations

We will start by creating visualizations and later add them to a single dashboard. Starting with the scatter plots to find the relationship between Sales and the factors governing it.

from bokeh.plotting import figure, output_file, show


p1 = figure(plot_width=400, plot_height=400)['TV'], df['Sales'], size=2, color="navy", alpha=0.5)


As you can see here Bokeh not only creates visualization but also provides different functions as shown in the image, the visualization is highly interactive and downloadable.

Similarly, we will create the visualization for the other two attributes against the Sales.


p2 = figure(plot_width=400, plot_height=400)['Radio'], df['Sales'], size=2, color="navy", alpha=0.5)



p3 = figure(plot_width=400, plot_height=400)['Newspaper'], df['Sales'], size=2, color="navy", alpha=0.5)



As you can see here we have created three scatter plots of Sales(Dependent Variable) vs. Newspaper, TV, Radio( Independent Variable)

Next, we will create the distribution plots according to the ‘Sales’ of all the numerical attributes.

fig1 = figure(plot_width=400, plot_height=400)

fig1.vbar(x=df['Sales'], bottom=0, top=df['TV'],

          color='blue', width=0.75, 




fig2 = figure(plot_width=400, plot_height=400)

fig2.vbar(x=df['Sales'], bottom=0, top=df['Radio'],

         color='red', width=0.75, 

See Also




fig3 = figure(plot_width=400, plot_height=400)

fig3.vbar(x=df['Sales'], bottom=0, top=df['Newspaper'],

         color='green', width=0.75, 




Similarly, we can create different types of plots and graphs according to our requirements. 

Next, we will design the layout and show these images in a single dashboard.

  1. Creating a Dashboard

For getting all these images in a single layout we need to define the layout of the dashboard.

We will use the grid layout and visualize the dashboard in a grid format.

from bokeh.layouts import gridplot

grid = gridplot([[p1, p2, p3], [fig1, fig2, fig3]], plot_width=250, plot_height=250)



As you can see in the image we have created a dashboard in a grid layout, it clearly shows the relationship between Sales and the numerical on which it is dependent.

This is just a basic layout/Dashboard which is easily created and can help you start designing dashboards in Bokeh if you are a beginner.


In this article, we learned about dashboards, how they help us to visualize the key performance indicators. We learned about Bokeh and how we can create dashboards using it, Bokeh is highly interactive and visually appealing. We can use this knowledge to create our own dashboards and visualize it.

What Do You Think?

Join Our Discord Server. Be part of an engaging online community. Join Here.

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top