I m trying to create a plot to display circle based on the status of checkbox. But not able to do so below is the code I m using
Bokeh version -2.2.3
from bokeh.layouts import column, row
from bokeh.plotting import figure, curdoc
from bokeh.models import HoverTool, Slider, CheckboxGroup
x=2
y=1
plot = figure(plot_height=300, plot_width=300,
x_range=(-x, x), y_range=(-y, y))
shapes_list = [plot.circle(
x=0, y=0, size=2, fill_alpha=.1), 'Square', 'Rectangle']
def display_shapes(flag):
for i in flag:
print(i, shapes_list[i], type(shapes_list[i]), shapes_list[i].glyph)
shapes_list[i].visible = True
def update_data(attrname, old, new):
x = xslider.value
y = yslider.value
x_plist = []
y_plist = []
z = x if x >= y else y
for j in range(-x, x+1, 1):
for i in range(-y, y+1, 2):
x_plist.append([j, j, j+1, j+1])
if i == -y:
y_plist.append([i+2, i+2, i+2, i])
else:
y_plist.append([i-2, i, i, i-2])
if j == 6:
print(j, j, j+1, j+1)
print(i-2, i, i, i-2)
print(shapes.active)
display_shapes(shapes.active)
plot.x_range.start = -z + 1
plot.y_range.start = -z+1
plot.x_range.end = z+1
plot.y_range.end = z+1
#hoverp = HoverTool(tooltips=[('$x-$y','@xs-@ys')], renderers=[pt])
pt.data_source.data['xs'] = x_plist
pt.data_source.data['ys'] = y_plist
x_plist = []
y_plist = []
for j in range(-x, x+1, 1):
for i in range(-y, y+1, 2):
x_plist.append([j, j, j+1, j+1])
if i == -18:
y_plist.append([i+2, i+2, i+2, i])
else:
y_plist.append([i-2, i, i, i-2])
xs = x_plist
ys = y_plist
shapes = CheckboxGroup(labels=['Circle', 'Square', 'Rectangle'])
xslider = Slider(title="X", value=5, start=0, end=10, step=1)
yslider = Slider(title="Y", value=6, start=0, end=10, step=1)
pt = plot.patches(xs, ys, fill_color='white', line_color='grey', line_alpha=.5)
hoverp = HoverTool(tooltips=[('$x-$y', '@hs')], renderers=[pt])
plot.add_tools(hoverp)
plot.axis.visible = True
plot.grid.visible = False
for w in [xslider, yslider]:
w.on_change('value', update_data)
shapes.on_change('active', update_data)
curdoc().add_root(row(plot, column(xslider, yslider, shapes), width=800))