How to use bokeh.layouts.GridSpec?

Viewed 270

Looking at https://github.com/Maluuba/bokeh/blob/master/bokeh/layouts.py I have a hard time figuring out how to actually show the result of the following code:

from bokeh.layouts import GridSpec
from bokeh.plotting import figure, show

fig1 = figure() #... plotting..
fig2 = figure() #... plotting..
fig3 = figure() #... plotting..
fig4 = figure() #... plotting..
fig5 = figure() #... plotting..

gspec = GridSpec(2, 3)
gspec[0, 0:2] = fig1 
gspec[0, 2] = fig2 
gspec[1, 0] = fig3 
gspec[1, 1] = fig4 
gspec[1, 2] = fig5

show(gspec)  # where to use sizing_mode='stretch_both' ??

My goal is to plot fig1 over the span of 2 columns on row 1 and having figures 2-5 as the same size. All figures need to dynamically change size depending on window size. Anyone have an idea?

I´m using bokeh 1.4

1 Answers

I haven't been able to span across columns using bokeh.layouts.GridSpec but here is a solution using bokeh.layouts.layout and specifying plot_width when creating the figures. I'm using bokeh-1.4.0

import bokeh
import bokeh.plotting

fig1 = bokeh.plotting.figure(plot_width=400, plot_height=200)
fig1.line([0,1],[0,1])
fig2 = bokeh.plotting.figure(plot_width=200, plot_height=200)
fig2.line([0,1],[1,0])
fig3 = bokeh.plotting.figure(plot_width=200, plot_height=200)
fig3.line([0,1,2],[1,0,1])
fig4 = bokeh.plotting.figure(plot_width=200, plot_height=200)
fig4.line([0,1,2],[0,1,0])
fig5 = bokeh.plotting.figure(plot_width=200, plot_height=200)
fig5.line([0,1,2],[0,0,1])

layout = bokeh.layouts.layout([
    [fig1,fig2],
    [fig3,fig4,fig5]

])
bokeh.io.show(layout)

the output looks as shown below: enter image description here

Related