How to use bokeh slider to update plot range?

时光毁灭记忆、已成空白 提交于 2020-02-25 10:19:07

问题


I am making a Bokeh dashboard in Python 3, and one of my main plots in-progress is a scatterplot. I have the entire plot made, but I am looking for a way to have two sliders (x and y) to specify the range displayed based on where they are slid to.

p6 = figure(title = 'Average Duration and Number of Calls by Topic in Top Departments',
        y_range=(0,13000), tools=["hover", 'box_zoom', 'reset', 'save'], tooltips="@Topic; @Seconds seconds of average duration; @Count total calls")

My not working slider code is like this:

y_range_slider = RangeSlider(start=0, end=13000, 
    value=(0,13000), step=20, title="Zoom by Number of Total Calls")


def callback(attr, old, low, high):

    low, high = y_range_slider.value

    #what do I need to do here to update range??

slider.on_change('value', callback)

回答1:


Use the values to update the range start/end:

def callback(attr, old, low, high):
    low, high = y_range_slider.value

    p6.y_range.start = low
    p6.y_range.end = high


来源:https://stackoverflow.com/questions/52764911/how-to-use-bokeh-slider-to-update-plot-range

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!