
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Visualize Multiple Bar Plots in Python Using Bokeh
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-
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.
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
Let us see an example −
Example
from bokeh.plotting import figure, output_file, show from bokeh.transform import dodge labs = ['label_1', 'label_2', 'label_3'] vals = ['val_1','val_2','val_3'] my_data = {'labs':labs, 'val_1':[2,5,11], 'val_2':[34,23,1], 'val_3':[25, 34, 23] } fig = figure(x_range = labs, plot_width = 300, plot_height = 300) fig.vbar(x = dodge('labs', -0.25, range = fig.x_range), top = 'val_1', width = 0.2,source = my_data, color = "green") fig.vbar(x = dodge('labs', 0.0, range = fig.x_range), top = 'val_2', width = 0.2, source = my_data,color = "cyan") fig.vbar(x = dodge('labs', 0.25, range = fig.x_range), top = 'val_3', width = 0.2,source = my_data,color = "blue") show(fig)
Output
Explanation
The required packages are imported, and aliased.
The figure function is called along with plot width and height.
The data is defined in lists.
The ‘output_file’ function is called to mention the name of the html file that will be generated.
The ‘vbar’ function present in Bokeh is called, along with data.
The ‘show’ function is used to display the plot.