问题
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