Bokeh layouts

In order to make good graphical analysis and make plots visually attractive you can make use of layouts. The use of layouts, tabs, and grids enhances your plots and create possibilities like using the same axes.

For demonstration purpose, we first create 3 individual plots of different shapes and heights

import pandas as pd
import numpy as np
from bokeh.plotting import figure, show, ColumnDataSource
from bokeh.io import output_notebook
output_notebook()

Loading BokehJS ...

#Create plot 1

fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]

plot1 = figure(x_range=fruits, plot_height=250, plot_width=400, 
        title="Fruit Counts",
        toolbar_location=None, tools="")
plot1.vbar(x=fruits, top=counts, width=0.9, color = "#c9d9d3")

show(plot1)
Plot 1
Plot 2
plot 3

Plots in a row layout

In order to plot three plots in a horizontal row we use code as shown below

Plots in a column layout

We can see that the three plots are simply stacked together side by side. If we would like the plots stacked vertically we should use column

Plot in a nested layout

Plot in a grid, similar to nested layout, but only one

Combining the two can create a nested layout

Tabbed layout

It might be more efficient to view a single plot a time but have multiple plots on a panel. Bokeh offers the tab layout, where each plot is stored in a single tab and it can be assessed by clicking on the tab

plot in a tabbed layout

In the example below we show one child on one tab, but two childs by the use of column on the other tab

Plot in a grid layout

A gird layout combines rows and columns and nested layouts and allows you to create plots in several directions. The grid layout is more versatile than the nested layout and you can create attractive layouts

Linking plots together

Sometimes you want to compare plots with each other and therefore, you need the same y-range. The following code illustrates this

plots with same y-axis

Last updated