简体   繁体   English

散景,动态更改图宽

[英]bokeh, dynamically change plot width

I'm trying to change plot width when taptool selects something. 我正在尝试在taptool选择某些内容时更改绘图宽度。 I invoke this using bokeh serve, and navigating to the localhost website 我使用bokeh服务调用此功能,然后导航到localhost网站

when I click on one of the rectangles, my console prints out "callback" and "callback2" but my plot doesn't change width. 当我单击一个矩形时,我的控制台会打印出“ callback”和“ callback2”,但我的绘图不会改变宽度。 What am I doing wrong? 我究竟做错了什么?

counts = [1*10**7,2*10**7,3*10**7]     #dummy data
l_edge = [x for x in range(len(counts))]
r_edge = [x + .85 for x in range(len(counts))]

data = {
    'height': counts,
    'leftEdges': l_edge,
    'rightEdges': r_edge,
}


p = figure()
s = ColumnDataSource(data)
p.add_tools(TapTool())

def callbackfcn(attr,old,new): 
    global p
    print('callback')
    p.width = np.random.choice([100,200,300,1000,10000])
    p.height = np.random.choice([100,200,300,1000,10000])
    print('callback2')

r = p.quad(top='height',bottom=0,
               left = 'leftEdges',right = 'rightEdges',
              source = s)        

r.data_source.on_change('selected',callbackfcn)              

layout = column(p)
curdoc().add_root(layout)

Have you tried instead including sizing_mode in your layout? 您是否尝试过在布局中包含sizing_mode? Take a look at the Bokeh docs for an example. Bokeh文档为例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM