- Bokeh Tutorial
- Bokeh Useful Resources
Use Bokeh server and set up event handlers. In this section, we shall see how to add Bokeh widgets and assign JavaScript callbacks. This widget is a clickable button generally used to invoke a user defined call back handler. The constructor takes following parameters −. Bokeh is a word with Japanese origins, defined as “the way the lens renders out-of-focus points of light. ” The word comes from the Japanese word boke (暈け or ボケ), which means “haze” or “blur.” (The “h” was introduced to help English speakers pronounce the word correctly BO - KEH.) It’s a subjective term — for example, “that image has good bokeh.
Bokeh Vs
- Selected Reading
In this chapter, we shall discuss about various types of axes.
Sr.No | Axes | Description |
---|---|---|
1 | Categorical Axes | The bokeh plots show numerical data along both x and y axes. In order to use categorical data along either of axes, we need to specify a FactorRange to specify categorical dimensions for one of them. |
2 | Log Scale Axes | If there exists a power law relationship between x and y data series, it is desirable to use log scales on both axes. |
3 | Twin Axes | It may be needed to show multiple axes representing varying ranges on a single plot figure. The figure object can be so configured by defining extra_x_range and extra_y_range properties |
Categorical Axes
In the examples so far, the Bokeh plots show numerical data along both x and y axes. In order to use categorical data along either of axes, we need to specify a FactorRange to specify categorical dimensions for one of them. For example, to use strings in the given list for x axis −
Example
With following example, a simple bar plot is displayed showing number of students enrolled for various courses offered.
Output
To show each bar in different colour, set color property of vbar() function to list of color values.
Output
To render a vertical (or horizontal) stacked bar using vbar_stack() or hbar_stack() function, set stackers property to list of fields to stack successively and source property to a dict object containing values corresponding to each field.
In following example, sales is a dictionary showing sales figures of three products in three months.
Output
A grouped bar plot is obtained by specifying a visual displacement for the bars with the help of dodge() function in bokeh.transform module.
The dodge() function introduces a relative offset for each bar plot thereby achieving a visual impression of group. In following example, vbar() glyph is separated by an offset of 0.25 for each group of bars for a particular month.
Output
Log Scale Axes
When values on one of the axes of a plot grow exponentially with linearly increasing values of another, it is often necessary to have the data on former axis be displayed on a log scale. For example, if there exists a power law relationship between x and y data series, it is desirable to use log scales on both axes.
Bokeh.plotting API's figure() function accepts x_axis_type and y_axis_type as arguments which may be specified as log axis by passing 'log' for the value of either of these parameters.
First figure shows plot between x and 10x on a linear scale. In second figure y_axis_type is set to 'log'
Output
Bokeh Library
Now change figure() function to configure y_axis_type=’log’
Output
Twin Axes
In certain situations, it may be needed to show multiple axes representing varying ranges on a single plot figure. The figure object can be so configured by defining extra_x_range and extra_y_range properties. While adding new glyph to the figure, these named ranges are used.
We try to display a sine curve and a straight line in same plot. Both glyphs have y axes with different ranges. The x and y data series for sine curve and line are obtained by the following −
Here, plot between x and y represents sine relation and plot between x and y2 is a straight line. The Figure object is defined with explicit y_range and a line glyph representing sine curve is added as follows −
We need an extra y range. It is defined as −
To add additional y axis on right side, use add_layout() method. Add a new line glyph representing x and y2 to the figure.
Bokeh Definition
This will result in a plot with twin y axes. Complete code and the output is as follows −