Anaconda Enterprise: Documentation

# Linking Plots

It’s often useful to link plots to add connected interactivity between plots. This section shows an easy way to do it using the bokeh.plotting interface.

## Linked Panning

It’s often desired to link pan or zooming actions across many plots. All that is needed to enable this feature is to share range objects between `figure()` calls.

    from bokeh.io import output_file, show
    from bokeh.layouts import gridplot
    from bokeh.plotting import figure

    output_file("panning.html")

    x = list(range(11))
    y0 = x
    y1 = [10-xx for xx in x]
    y2 = [abs(xx-5) for xx in x]

    # create a new plot
    s1 = figure(plot_width=250, plot_height=250, title=None)
    s1.circle(x, y0, size=10, color="navy", alpha=0.5)

    # create a new plot and share both ranges
    s2 = figure(plot_width=250, plot_height=250, x_range=s1.x_range, y_range=s1.y_range, title=None)
    s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)

    # create a new plot and share only one range
    s3 = figure(plot_width=250, plot_height=250, x_range=s1.x_range, title=None)
    s3.square(x, y2, size=10, color="olive", alpha=0.5)

    p = gridplot([[s1, s2, s3]], toolbar_location=None)

    # show the results
    show(p)

Now you have learned how to link panning between multiple plots with the bokeh.plotting interface.

## Linked Brushing

Linked brushing in Bokeh is expressed by sharing data sources between glyph renderers. This is all Bokeh needs to understand that selections acted on one glyph must pass to all other glyphs that share that same source.

The following code shows an example of linked brushing between circle glyphs on two different `figure()` calls.

    from bokeh.io import output_file, show
    from bokeh.layouts import gridplot
    from bokeh.models import ColumnDataSource
    from bokeh.plotting import figure

    output_file("brushing.html")

    x = list(range(-20, 21))
    y0 = [abs(xx) for xx in x]
    y1 = [xx**2 for xx in x]

    # create a column data source for the plots to share
    source = ColumnDataSource(data=dict(x=x, y0=y0, y1=y1))

    TOOLS = "box_select,lasso_select,help"

    # create a new plot and add a renderer
    left = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
    left.circle('x', 'y0', source=source)

    # create another new plot and add a renderer
    right = figure(tools=TOOLS, plot_width=300, plot_height=300, title=None)
    right.circle('x', 'y1', source=source)

    p = gridplot([[left, right]])

    show(p)