from bokeh.io import output_notebook, show
from bokeh.plotting import figure
output_notebook()
In the previous chapters we started to learn how to create single plots using differnet kinds of data. But we often want to plot more than one thing. Bokeh plots can be individually embedded in HTML documents, but it's often easier to combine multiple plots in one of Bokeh's built-in layouts. We will learn how to do that in this chapter
The cell below defines a few data variables we will use in examples.
x = list(range(11))
y0, y1, y2 = x, [10-i for i in x], [abs(i-5) for i in x]
The bokeh.layouts
modules provides the row
and column
functions to arrange plot objects in vertical or horizontal layouts. Below is an example of three plots arranged in a row.
from bokeh.layouts import row
# create a new plot
s1 = figure(width=250, height=250)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)
# create another one
s2 = figure(width=250, height=250)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
# create and another
s3 = figure(width=250, height=250)
s3.square(x, y2, size=10, color="olive", alpha=0.5)
# show the results in a row
show(row(s1, s2, s3))
# EXERCISE: use column to arrange a few plots vertically (don't forget to import column)
Bokeh also provides a gridplot
layout in bokeh.layouts
for arranging plots in a grid, as show in the example below.
from bokeh.layouts import gridplot
# create a new plot
s1 = figure(width=250, height=250)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)
# create another one
s2 = figure(width=250, height=250)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)
# create and another
s3 = figure(width=250, height=250)
s3.square(x, y2, size=10, color="olive", alpha=0.5)
# put all the plots in a gridplot
p = gridplot([[s1, s2], [s3, None]], toolbar_location=None)
# show the results
show(p)
# EXERCISE: create a gridplot of your own
Click on this link to go to the next notebook: 06 - Linking and Interactions.
To go back to the overview, click here.