☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Bokeh and gridplot

Community Support
giovanni
giovanni

I am trying the following code to produce 4 plots in two columns using the gridplot function.

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

outputfilename = r'c:\testing\test.html'
output_file(outputfilename)

n_plots = 4
x = [i for i in range(10)]
y = [i for i in range(10)]
df = {'x': x, 'y': y}
list_plots = []
source = ColumnDataSource(df)
TOOLS='hover,box_zoom,pan,xpan,ypan,wheel_zoom,reset,save,crosshair'
for i in range(n_plots):
    p = figure(tools=TOOLS)
    ts = p.line('x', 'y', source=source)
    legend = Legend(items=[('test', [ts])], location="center")
    legend.click_policy = 'hide'
    p.add_layout(legend, 'right')
    list_plots.append(p)

new_layout = []
for i in range(int(n_plots/2)):
    new_layout.append([list_plots[i * 2 + 1], list_plots[i * 2]])

grid = gridplot(new_layout)
save(grid)

I have two issues with the code above:

  1. the toolbar does not show the xpan and the ypan
  2. there is only one toolbar. How can I show an individual toolbar for each plot using gridplot?

Thanks in advance
Giovanni

⌁   Link to post
giovanni
giovanni

Thanks for that, I also tried the option with layout, but in my case I am forced to use griplot as I would like to leave some empty spaces and apparently this is possible only with griplot. If I try:

column(row(None, plot1), row(plot2, None)))

this throws the error:

ValueError: Only LayoutDOM items can be inserted into a row. Tried to insert: None of type <class 'NoneType'>

This is because None is not a LayoutDOM item. But if I do the same with griplot everything works OK.

⌁   Link to post

End of archived discussion · Replies are disabled