Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬Register for the Oct 27 webinar.

Y-axis autoscale with Range Selector - layout.on_change not recognized

Trying to autoscale the yaxis when using the range selector but seems to not be getting called at all? Trying to adapt solution found here to work with rangeselector. I currently have

def zoom(layout, x_range):
  print('yaxis updated')
  in_view = df.loc[figure.layout.xaxis.range[0]:figure.layout.xaxis.range[1]]
  figure.layout.yaxis.range = [in_view.High.min() - 10, in_view.High.max() + 10]

def build_plot():
  figure=go.FigureWidget(data=data, layout=layout)
  figure.layout.on_change(zoom, 'xaxis.range')

Right now I’m not even seeing the print statement in the console. Is this only possible with range slider or am I simply making some other mistake as only the xaxis is changing? Also, I’m rendering directly in html (flask render_template) not using juypter; originally I was just using go.Figure but I went to go.FigureWidget so I could use the on_change callback. Not certain where I should go at this point so any feedback is welcome.

Hi @cartier,

FigureWidget is a custom ipywidget (https://ipywidgets.readthedocs.io/en/stable/), so it will only work in the Jupyter context. The main options for this are the Jupyter notebook, JupyterLab, or voila (https://github.com/QuantStack/voila) for a standalone dashboard.

You could also do this using Dash (https://dash.plot.ly/) using a relayoutData callback.


Hey @jmmease thanks for letting me know. Looked at this post too but not sure they ever got it working…

Hi @mcox. Saw your post here that’s a little over 2years old. Just a shot in the dark but I was wondering if you ever made any progress. Running into a similar issue…