Scale update after calling curdoc()

I’m running bokeh server and
function is called when a widgets is changed like

p = figure(....)

def  adjustArea(y):
  y_max, y_min = np.max(y), np.min(y)
  gap = (y_max - y_min)/10
  p.y_range = Range1d(y_min-gap, y_max+gap)

It can change y_range of figure but its property is not refered after

curdoc().add_root(layout)

I can’t find the way figure property is refered.

Thank you

You should update the start and end properties of the existing y_range, not replace the entire range object with a new Range1d. Best practice with bokeh is always to make the smallest change possible (i.e. change properties on existing objects, don’t replace them)

I tried to modify code like

p.y_range.start = y_min - gap
p.y_range.end = ymax + gap

But i didn’t help.
I add the y_range property in definition of figure like

p = figure(tools=TOOLS, y_range=[0, 0])

Now figure scale is canged by updating y_range.

p = figure(tools=TOOLS)
p.y_range.start = y_min - gap
p.y_range.end =  ymax + gap

It can define the y_range only for initialization.But it can’t be updated.

Now it’s clear. Thanks