Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code example to reproduce bokeh layout problem
from numpy import array, random
from pandas import DataFrame
from bokeh.plotting import figure, curdoc
from bokeh.layouts import row, column, widgetbox
from bokeh.models.widgets import Button
def draw_plot(df):
f= figure(tools="save", background_fill_color="#EFE8E2",
title="", width=500, height=500)
xcol = df.columns[random.randint(len(df.columns))]
ycol = df.columns[random.randint(len(df.columns))]
f.circle(df[xcol], df[ycol])
f.xaxis.axis_label = xcol
f.yaxis.axis_label = ycol
return f
def add_to_axis(axis='x', figure_width=500):
if axis.lower() == 'y':
layout_y.children.append(draw_plot(data))
layout_y.width += figure_width
layout_x.width += figure_width
layout.width += figure_width
elif axis.lower() == 'x':
layout_x.children.append(row(draw_plot(data)))
layout_x.height += figure_width
layout.height += figure_width
def add_below():
add_to_axis('x')
def add_across():
add_to_axis('y')
add_below_button = Button(label='add below', width=150)
add_across_button = Button(label='add across', width=150)
add_below_button.on_click(add_below)
add_across_button.on_click(add_across)
arra = array([ random.random() for i in range(10) ])
arrb = array([ random.random() for i in range(10) ])
arrc = array([ random.random() for i in range(10) ])
arrd = array([ random.random() for i in range(10) ])
datadict = { 'A': arra,
'B': arrb,
'C': arrc,
'D': arrd }
data = DataFrame(datadict)
fig = draw_plot(data)
wbox = widgetbox([add_below_button, add_across_button], width=200)
layout_y = row(fig, width=600)
layout_x = column(layout_y, width=600)
layout = row(wbox, layout_x, width=wbox.width+layout_y.width, height=layout_x.height)
curdoc().add_root(layout)
curdoc().title = 'Layout Buttons'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.