简体   繁体   English

如何多次更新散景图中的图特征(悬停工具详细信息和x_range)?

[英]How to update plot characteristics (hovertool details and x_range) in a bokeh plot multiple times?

I have a bokeh plot that I would like to update the ranges (x_range and y_range) as well as the hovertool details (field names, etc.) when I update the source data in the plot. 我有一个散景图,当我更新图中的源数据时,我想更新范围(x_range和y_range)以及悬停工具详细信息(字段名称等)。 The things I've tried haven't worked yet. 我尝试过的事情还没有奏效。 Any help would be appreciated. 任何帮助,将不胜感激。 Here's an example of what I've tried. 这是我尝试过的例子。

def update_plot(*args):
    source = select_data();

    # Set ranges (not working)
    p.x_range = Range1d(0, source['x'].max())
    p.y_range = Range1d(0, source['y'].max())

    # How to change hovertool here?

figureTools = [HoverTool()]
p = figure(plot_height=600, plot_width=700, title='', tools=figureTools)
p.circle(x='x', y='y', source=source, line_color=None)

widget = widgets.Dropdown(options=['1', '2', '3'])
widget.observe(update_plot, 'value')

update_plot();
show(p);

You can put show(p) inside update, that works for me. 您可以将show(p)放在update里面,这对我有用。 For example, 例如,

def update_plot(*args):
    source = select_data();

    # Set ranges (not working)
    p.x_range = Range1d(0, source['x'].max())
    p.y_range = Range1d(0, source['y'].max())

    # How to change hovertool here?
    show(p);

figureTools = [HoverTool()]
p = figure(plot_height=600, plot_width=700, title='', tools=figureTools)
p.circle(x='x', y='y', source=source, line_color=None)

widget = widgets.Dropdown(options=['1', '2', '3'])
widget.observe(update_plot, 'value')

update_plot();
show(p);

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

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