I can't find a way to override the behavior of the reset tool

I have a plot and a dropdown menu widget. According to the choice from the menu, a different range will be configured for the y axis.

The code looks something like this:

plt = figure(plot_width=1500, plot_height=500,
x_axis_type=“datetime”,
tools=[‘xzoom_in’, ‘xzoom_out’, ‘xpan’, ‘reset’])

plt.y_range = Range1d(0, 1)

select_item = Select(title = ‘Select an item’,
value = data_src[0],
options = list(data_src))

def update_src(item):
feature_list = read_data_for_un(item)
plt.y_range.start = -0.3
plt.y_range.end = len(feature_list) - 0.8

select_item.on_change(‘value’, lambda att, old, new: update_src(new))

Draw the initial graph

update_src(data_src[0])

``

By running the above code, I discover that the initial range of y axis is determined by update_src(data_src[0]) in the above code snippet.

Now if I select an item, say data_src[1], the range of y axis is adjusted acoording to data set of the selected item data_src[1].

I zoom in the graph and press Bokeh’s default reset tool while I am still in data_src[1], then the range of the y axis goes back to when update_src(data_src[0]) was selected, while my intention is to restore the range for data_src[1]

Is there some way to override the behavior of reset tool or is there any way to make it behave as I intend?

My question seems similar to the question in the following post but I still cannot figure out how to do it:

https://stackoverflow.com/questions/39992566/how-to-make-figure-changes-survive-the-reset-button-in-bokeh

Ah, I should have searched on GH!

I’ve got some help from here:

For me to restore y_range, simply doing this works:

def callback(event):

plt.y_range.start = plt_prev_y_start
    plt.y_range.end = plt_prev_y_end

  plt.on_event(Reset, callback)

The guide in http://bokeh.pydata.org/en/latest/docs/reference/events.html seems to be misleading though.
'''

from bokeh.events import ButtonClick
from bokeh.models import Button

button = Button()

def callback(event):
print(‘Python:Click’)

button.on_event(ButtonClick, callback)

‘’’

because the above code example may make people try something like following code by analogy:
'''
reset_tool = ResetTool()
plt.add_tools(reset_tool)
reset_tool.on_event(Reset, callback)
'''

, which actually does nothing.

2017년 9월 22일 금요일 오후 7시 14분 37초 UTC+9, Sijun Cho 님의 말:

···

I have a plot and a dropdown menu widget. According to the choice from the menu, a different range will be configured for the y axis.

The code looks something like this:

plt = figure(plot_width=1500, plot_height=500,
x_axis_type=“datetime”,
tools=[‘xzoom_in’, ‘xzoom_out’, ‘xpan’, ‘reset’])

plt.y_range = Range1d(0, 1)

select_item = Select(title = ‘Select an item’,
value = data_src[0],
options = list(data_src))

def update_src(item):
feature_list = read_data_for_un(item)
plt.y_range.start = -0.3
plt.y_range.end = len(feature_list) - 0.8

select_item.on_change(‘value’, lambda att, old, new: update_src(new))

Draw the initial graph

update_src(data_src[0])

``

By running the above code, I discover that the initial range of y axis is determined by update_src(data_src[0]) in the above code snippet.

Now if I select an item, say data_src[1], the range of y axis is adjusted acoording to data set of the selected item data_src[1].

I zoom in the graph and press Bokeh’s default reset tool while I am still in data_src[1], then the range of the y axis goes back to when update_src(data_src[0]) was selected, while my intention is to restore the range for data_src[1]

Is there some way to override the behavior of reset tool or is there any way to make it behave as I intend?

My question seems similar to the question in the following post but I still cannot figure out how to do it:

[https://stackoverflow.com/questions/39992566/how-to-make-figure-changes-survive-the-reset-button-in-bokeh](https://stackoverflow.com/questions/39992566/how-to-make-figure-changes-survive-the-reset-button-in-bokeh)