- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can Bokeh be used to visualize bar plot in Python?
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
from bokeh.plotting import figure, output_file, show xvals = ['label_1', 'label_2', 'label_3'] yvals = [56, 78, 99] fig = figure(x_range = xvals, plot_width = 400, plot_height = 300) cols = ['navy','cyan','orange'] fig.vbar(x = xvals, top = yvals, color = cols, width = 0.5) show(fig)
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 color list can also be defined to give different colors to every bar in the bar graph.
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.
Kickstart Your Career
Get certified by completing the courseGet Started