Bokeh introduction

source: https://github.com/PacktPublishing/Hands-on-Data-Visualization-with-Bokeh

Key definitions

The following are some key definitions related to Bokeh

  • Applications: The Bokeh application is a rendered document that runs in the browser

  • Glyphs: The building blocks of Bokeh, the geometric shapes that make up every element in the plot, like lines, rectangles, or circles.

glyphs explained (www.DataCamp.com)
  • Widgets: sliders, dropdown menus, and tools to make the plot interactive

Plot output

You can use output_file to render your plot as an HTML file

output_file('plot.html')

Or you can use directly in a jupyter notebook using

output_notebook()

Interface

Bokeh provides a plotting interface known as bokeh.plotting. The interface is the Figure class, which makes it possible to draw up the plot or plots on a 'canvas'.

from bokeh.plotting import figure
p = figure(plot_width = 500, plot_height = 400, tools="pan, hover")

The variable p holds information about the plot including the width, height and the tools that will be used. Since figure is the main class, methods such as line, lables, legends and so on can be added to our diagram to create the plot

p.line(x, y)
p.xaxis.axis_label = 'CO2 (mg/l)'
p.yaxis.axis_label = 'enzyme activity'

When the plot is drawn the plot can be outputted:

output_file('line_plot.html') # not in the case of using notebook
show(p)

Last updated

Was this helpful?