How can Bokeh library be used to plot horizontal bar plots using Python?

Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plot using HTML and JavaScript. This indicates that it is useful while working with web-based dashboards.

Visualizing data is an important steps since it helps understand what is going on in the data without actually looking at the numbers and performing complicated computations.

Bokeh can be easily used in conjunction with NumPy, Pandas, and other Python packages. It can be used to produce interactive plots, dashboards, and so on.

It helps in communicating the quantitative insights to the audience effectively.

Bokeh converts the data source into a JSON file. This file is used as an input to BokehJS, which is a JavaScript library. This BokehJS is written in TypeScript that helps render visualization on modern browsers.

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 −


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
fig = figure(plot_width = 400, plot_height = 200)
fig.hbar(y = [2, 5, 9, 1], height = 1, left = 0, right = [1, 6, 3, 9], color = "Cyan")
output_file('bar plot.html')



  • The required packages are imported, and aliased.

  • The figure function is called by passing width and height of plot.

  • The ‘output_file’ function is called to mention the name of the html file that will be generated.

  • The ‘hbar’ function present in Bokeh is called along with data points.

  • The ‘show’ function is used to display the plot.

Updated on: 18-Jan-2021


Kickstart Your Career

Get certified by completing the course

Get Started