£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Learn how to link plots together

Plots can be linked together to provide a wholesome experience. In cases where we have to compare plots, we can show multiple plots together in rows or columns to make comparison easy.

Consider this example: When showing different facets of the same data across different plots, linking plots together can help by using the same range for each of their axes.

To link the plots, begin with a normal figure and then reference the linked figure ranges from the original to achieve multiple plots together.

In this step, we will link different plots together with the help of demonstration on Jupyter Notebook using Bokeh. We will use three figures for this demonstration.

### Step 1

Link the axes. The first two axes will have their x-axes linked, so panning one will update the x-axis of the other. The second two will be linked on y-axes, so panning one updates the y-axis of the other.

Code:

x = [1, 2, 3, 4]y0 = [10, 8, 6, 2]y1 = [2, 9, 4, 7]y2 = [3, 6, 1, 5]scatter_plot = figure(plot_width=figure_width, plot_height=figure_height)scatter_plot.scatter(x, y0, color="red")

### Step 2

Next, the second figure will be linked on the x-axis only. We supply the x_range keyword argument when creating the figure, passing in the first plot’s x_range attribute.

Code:

line_plot = figure(plot_width=figure_width, plot_height=figure_height, x_range=scatter_plot.x_range)line_plot.line(x, y0, color="blue")

### Step 3

Finally the third figure will link on the y-axis by sharing the y_range with the second figure:

Code:

circle_plot = figure(plot_width=figure_width, plot_height=figure_height, y_range=line_plot.y_range)circle_plot.circle(x, y2, color="green", size=20)

### Step 4

Now, plot the figures in a row.

Code:

show(row(scatter_plot, line_plot, circle_plot))

Output:

## What do you observe?

Looking at the outputs, what do you think of the plot now? Is it much easier to understand the comparison among the three figures? Would you still prefer these plots shown as separate figures?

Share your thoughts in the comment section below.